collision problem

Blitz3D Forums/Blitz3D Beginners Area/collision problem

po(Posted 2004) [#1]
If I have made a cube and a sphere that are supposed to colide and slide, it will work fine. But if I make the cube taller, the sphere would only collide with the area the former cube used to be. Here is what I have:
Graphics3D 800,600

Const CUBE_COL=1
Const CUBE_COL2=3
Const PLAYER_COL=2

Global speed#,player
Global turn#

SetBuffer BackBuffer()

camera=CreateCamera()
CameraViewport camera,0,0,800,600
PositionEntity camera,0,0,-5

light=CreateLight()

cube=CreateCube()
PositionEntity cube,-8,0,5
ScaleEntity cube,1,9,1
EntityType cube,CUBE_COL

cube2=CreateCube()
PositionEntity cube2,8,0,5
ScaleEntity cube2,1,9,1
EntityType cube2,CUBE_COL2

player=CreateSphere(12)
PositionEntity player,0,-4,5
EntityType player,PLAYER_COL

Collisions PLAYER_COL,CUBE_COL,3,2
Collisions PLAYER_COL,CUBE_COL2,3,2

speed#=0.08
turn#=0

While Not KeyHit(1)

If KeyDown(200) Then 
	MoveEntity player,speed#,0,0
EndIf

If KeyDown(203) Then
	turn#=3 
	TurnEntity player,0,0,turn#
EndIf

If KeyDown(205) Then 
	turn#=-3
	TurnEntity player,0,0,turn#
EndIf 

If EntityCollided(player,CUBE_COL) Then

EndIf

If EntityCollided(player,CUBE_COL2) Then

EndIf

UpdateWorld
RenderWorld
Flip

Wend

End


How do you make the collision recocnise how tall and big the 2 cubes are?


jhocking(Posted 2004) [#2]
Your Collisions commands are wrong. You are using the third collision type, sphere to box, when you should be using the second, sphere to polygon. Sphere-to-box detects collisions against an invisible collision box, whereas you want to collide against the polygons of the models. Change the collision statements to read Collisions PLAYER_COL,CUBE_COL,2,2

If you want to use sphere-to-box collision detection you are going to have to use EntityBox to set the collision boxes. Without using EntityBox to set them manually, the collision boxes default to 1,1,1.

Along the same lines, you should use EntityRadius to define the collision sphere for the player. In this case the default of radius 1 works, but with different sized players you will need to set EntityRadius explicitly.


_PJ_(Posted 2004) [#3]
ScaleEntity does NOT affect collision radii.