Need help pushing objects

Blitz3D Forums/Blitz3D Programming/Need help pushing objects

RiverRatt(Posted 2004) [#1]
I was suprized to find out that there is no examples on how to push objects around like in tomb raider, or resident evil. like when they move blocks or pillars and stuff. If anyone would like to help me with this code I will post it in the code base. Here is what I have so far. A sphere and a cube; player controls sphere with keys w,s,a and d;
What I want to happen is when sphere collides with box (for example from the top of the cube, the cube should move down)or vise versa. I think I need to use the comands collision x,y,z but not sure how to do that.
Another way I tried is if sphere is to check if sphere is higher or lower, to the right of or to the left of box at time of collision, so that box would move acordingly.
Do I at least have a clue?

Graphics3D 640,480,16
SetBuffer BackBuffer()

Const cube_col=1
Const sphere_col=2


light= CreateLight()


camera=CreateCamera()
PositionEntity camera,0,40,0

Type cubedata
Field x#,y#
End Type

Type circledata
Field x#,y#
End Type

box.cubedata = New cubedata
box\x#=-10
box\y#=40
cube= CreateCube()
ScaleEntity cube,1,2,2
PositionEntity cube,box\x#,box\y#,20
EntityColor cube,255,0,0
EntityType cube,cube_col;colitionccccccccccccccccccccccccccccc
;EntityBox entity,x#,y#,z#,width#,height#,depth#
EntityBox cube,-10,40,20,1,2,2
;CollisionX# ( entity,index )
;CollisionX# ( cube,1 )
;CollisionY# ( cube,1 )

;player
circle.circledata = New circledata
circle\x#=10
circle\y#=40
sphere= CreateSphere()
EntityColor sphere,0,0,255

PositionEntity sphere,circle\x#,circle\y#,20
EntityType sphere,sphere_col;colitionccccccccccccccccccccccccccccc

Collisions sphere_col,cube_col,2,3

Global rsx#=-.25
Global lsx#=.25
Global rsy#=-.25
Global lsy#=.25

While Not KeyHit(1)

If KeyDown(30) MoveEntity sphere,rsx#,0,0
If KeyDown(32) MoveEntity sphere,lsx#,0,0
If KeyDown(17) MoveEntity sphere,0,lsy#,0
If KeyDown(31) MoveEntity sphere,0,rsy#,0

UpdateWorld()
RenderWorld()
Text 10,20,circle\x + circle\y
If EntityCollided(sphere,cube_col)
Text 370,80,"Collided !!!"
TranslateEntity cube,-.25+(bx#*2),0,0
EndIf

Text 335,500,"Collision Detection"

Flip
Wend
End


Techlord(Posted 2004) [#2]
RiverRatt,

Your code works great,not sure what trouble your having.


RiverRatt(Posted 2004) [#3]
The cube can only be pushed in one direction.
I Want the sphere to be able to push the cube in all four
x and y directions.


Ross C(Posted 2004) [#4]
Please only post in the one forum :) Thanks


Brendane(Posted 2004) [#5]
Is this kind of what you're after?

Graphics3D 800,600,0,2


cam=CreateCamera()
PositionEntity cam,0,5,-20


sphere=CreateCone()
RotateMesh sphere,90,0,0
PositionEntity sphere,-5,0,0
EntityType sphere,1

cube=CreateCube()
EntityType cube,2


light=CreateLight()
PositionEntity light,-5,-5,-5
PointEntity light, cube


Collisions 1,2,3,2


While Not KeyHit(1)

If KeyDown(200) MoveEntity sphere,0,0,0.2
If KeyDown(208) MoveEntity sphere,0,0,-0.2
If KeyDown(203) TurnEntity sphere,0,3,0
If KeyDown(205) TurnEntity sphere,0,-3,0

If EntityCollided(sphere,2)
For n=1 To CountCollisions(sphere)
ent = CollisionEntity(sphere,n)
x#=CollisionNX(sphere,n)/10
y#=CollisionNY(sphere,n)/10
z#=CollisionNZ(sphere,n)/10

TranslateEntity ent,-x#,-y#,-z#
Next
EndIf

UpdateWorld
RenderWorld
Flip
Wend


Ross C(Posted 2004) [#6]
http://www.blitzbasic.com/Community/posts.php?topic=30881


Brendane(Posted 2004) [#7]
Ah, sorry.