Collisions And Animate, PLEASE HELP!

Blitz3D Forums/Blitz3D Programming/Collisions And Animate, PLEASE HELP!

Boiled Sweets(Posted 2003) [#1]
Hi,

please try the following code (move the ball with the cursor keys) try to get the ball to collide with the cube.
Collisions fail!

Then comment out the "animate cube, 1" line. Collisions work. WHY IS THIS?


; Collisions Example
; ------------------

Graphics3D 640,480
SetBuffer BackBuffer()

; Set collision type values
type_ground=1
type_character=2
type_scenery=3

camera=CreateCamera()
RotateEntity camera,45,0,0
PositionEntity camera,0,15,-10

light=CreateLight()
RotateEntity light,45,0,0

; Create cube 'ground'
cube=CreateCube()
ScaleEntity cube,10,10,10
EntityColor cube,0,127,0
EntityType cube,type_ground
PositionEntity cube,0,-5,0

; Create sphere 'character'
sphere=CreateSphere( 32 )
EntityColor sphere,127,0,0
EntityRadius sphere,1
EntityType sphere,type_character
PositionEntity sphere,0,7,0

; Enable collisions between type_character and type_ground
Collisions type_character,type_ground,2,2


; Create cube 'scenery'
cube=CreateCube()
ScaleEntity cube,2,2,2
EntityColor cube,0,0,127
EntityRadius cube,2
EntityBox cube,-2,-2,-2,4,4,4
EntityType cube,type_scenery
RotateEntity cube,0,45,0
PositionEntity cube,4,7,4

	EntityColor cube, 255,0, 0
	
	SetAnimKey cube,0,0,1,1

	TurnEntity cube,0,90,True
	SetAnimKey cube,90,0,1,1

	TurnEntity cube,0,90,0,True
	SetAnimKey cube,180,0,1,1
	
	TurnEntity cube,0,90,0,True
	SetAnimKey cube,270,0,1,1

	TurnEntity cube,0,90,0,True
	SetAnimKey cube,360,0,1,1
	
	AddAnimSeq cube, 360
	Animate cube,1


; Set collision method and response values
method=2
response=2

method_info$="ellipsoid-to-polygon"
response_info$="slide1"

While Not KeyDown( 1 )

x#=0
y#=0
z#=0

If KeyDown( 203 )=True Then x#=-0.1
If KeyDown( 205 )=True Then x#=0.1
If KeyDown( 208 )=True Then z#=-0.1
If KeyDown( 200 )=True Then z#=0.1

MoveEntity sphere,x#,y#,z#
MoveEntity sphere,0,-0.02,0 ; gravity

; Change collision method
If KeyHit( 50 )=True
method=method+1
If method=4 Then method=1
If method=1 Then method_info$="ellipsoid-to-sphere"
If method=2 Then method_info$="ellipsoid-to-polygon"
If method=3 Then method_info$="ellipsoid-to-box"
EndIf

; Change collision response
If KeyHit( 19 )=True
response=response+1
If response=4 Then response=1
If response=1 Then response_info$="stop"
If response=2 Then response_info$="slide1"
If response=3 Then response_info$="slide2"
EndIf

;TurnEntity cube, 0,1,0


; Enable collisions between type_character and type_scenery
Collisions type_character,type_scenery,method,response

; Perform collision checking

UpdateWorld

RenderWorld

Text 0,0,"Use cursor keys to move sphere"
Text 0,20,"Press M to change collision Method (currently: "+method_info$+")"
Text 0,40,"Press R to change collision Response (currently: "+response_info$+")"
Text 0,60,"Collisions type_character,type_scenery,"+method+","+response

Flip

Wend

End




jfk EO-11110(Posted 2003) [#2]
Seems like the setaminkey commands are not used by many people. maybe that's the reason why they are not so complete like other command familys.
BTW. Did you try to set both:

Collisions type_character,type_ground,2,2
Collisions type_ground,type_character,2,2


Boiled Sweets(Posted 2003) [#3]
Yes, it would appear that Blitx is unable to handle collision detection between 2 moving entities unless BOTH of them are spheres...

Can someone please verify this?


Beaker(Posted 2003) [#4]
That is correct.


Boiled Sweets(Posted 2003) [#5]
So how do other people do it?


simonh(Posted 2003) [#6]
Some people use line picks. There is an example in the code archives by Ken Lynch that uses line picks to have a moving ball collide with a moving platform.