3D collision problem

Blitz3D Forums/Blitz3D Programming/3D collision problem

Duff(Posted 2013) [#1]
Hello all,

Below I have listed to simple 3D collision programs. One works properly and the other does not. I would appreciate any help on explaining why. Thank you,

Duff
;========working code===
Graphics3D 1024,768,16,2
SetBuffer BackBuffer()
camera=CreateCamera()
light = CreateLight()
sphere=CreateSphere(16)
PositionEntity sphere,2,0,5
EntityColor sphere,255,0,0
EntityType sphere,1
EntityRadius sphere,1
cube=CreateCube()
PositionEntity cube,-2,0,5
EntityType cube,2
EntityRadius cube,1
Collisions 1,2,1,1

While Not KeyHit(1)
If KeyDown(57) Then MoveEntity sphere,-.02,0,0
UpdateWorld()
RenderWorld()
If EntityCollided(sphere,2) Then Text 1,1,"collision!"
Flip
Cls
Wend
End
;==========non-working code======
Graphics3D 1024,768,16,2
SetBuffer BackBuffer()
camera=CreateCamera()
light = CreateLight()
cube=CreateCube()
PositionEntity cube,-2,0,5
EntityType cube,1
EntityRadius cube,1
sphere=CreateSphere(16)
PositionEntity sphere,2,0,5
EntityColor sphere,255,0,0
EntityType sphere,2
EntityRadius sphere,1
Collisions 1,2,1,1

While Not KeyHit(1)
If KeyDown(57) Then MoveEntity sphere,-.02,0,0
UpdateWorld()
RenderWorld()
If EntityCollided(cube,2) Then Text 1,1,"collision!"
Flip
Cls
Wend
End


RemiD(Posted 2013) [#2]
Easy :
When you define the collisions, you must define the colliders emitter group against the colliders receiver group.

In this case :
Collisions 1,2,1,1
means the colliders emitter group is the group "1", the colliders receiver group is the group "2"

Because on this line :
If KeyDown(57) Then MoveEntity sphere,-.02,0,0
you move the sphere, and the sphere is not defined has being a collider emitter against another collider receiver, nothing happens.

If you want the sphere to be a collider emitter against the cube (the collider receiver), you have to write :
Collisions 2,1,1,1

If you want the cube to be also a collider emitter against the sphere (the collider receiver), you have to add another line :
Collisions 1,2,1,1

Try this :



Rick Nasher(Posted 2013) [#3]
Collisions 2,1,1,1 works ok.

Bit of a guess here:

Collission command's response is stop the moving(source) object and as the cube is not moving this has already stopped and cannot respond like that. So perhaps command only is valid to test+respond on moving objects as source object otherwise the stop response wouldn't make sense?

If the cube is moving it's response is to stop:
Graphics3D 1024,768,16,2
SetBuffer BackBuffer()
camera=CreateCamera()
light = CreateLight()

;
cube=CreateCube()
PositionEntity cube,2,0,5

EntityColor cube,255,0,0
EntityType cube,1
EntityRadius cube,1

;
sphere=CreateSphere(16)
PositionEntity sphere,-2,0,5
EntityType sphere,2
EntityRadius sphere,1
Collisions 1,2,1,1

While Not KeyHit(1)
 If KeyDown(57) Then MoveEntity cube ,-.02,0,0
 UpdateWorld()
 RenderWorld()

 If EntityCollided(cube,2) Then Text 1,1,"Cube collided!"

 Flip 
 Cls
Wend
End 


But of course I'm guessing here. You can of course create a testcase in which you set up a double check and move both objects towards each other.