Collisions: Need some advices please !

Blitz3D Forums/Blitz3D Beginners Area/Collisions: Need some advices please !

etxtra(Posted 2011) [#1]
hi everyone ! I don't understand how collisions works in Blitz3D, I need some explanations, advices and tricks.
-How do you perform sliding collisions ?
-how do you perform raycasting (a method that detect if an object is between two points) ?
-How do you set collisions to box or to polygons for a given object ?
-simply, how do you know when two objects collide with each other?

please, can you tell me ? I've read the manual but I'm still "lost"...

Last edited 2011


Warner(Posted 2011) [#2]
1. Use the "Collsions" command. It is the 4th parameter.
2. Use LinePick, after that read PickedEntity() to find out if any entities were picked. You need to enable picking on Entities first by setting "EntityPickMode ent, 2" for each entity.
3. If the object is moving, you can't, only sphere is allowed.
If the object is standing still, use the "Collisions" command. It is the 2nd parameter.
4. Either use MeshesIntersect (might be slow) or enable collisions, then use CollisionEntity() or EntityCollided().

Hopefully this example helps:



etxtra(Posted 2011) [#3]
Hi everyone ! There is something that is driving me crazy : Collisions against a simple cube aren't working ! explanations: I create 8 spheres, like this :
	For Z = 0 To 7
		T_Intelligence_Artificielle_F ( 0, Z ) = CreateSphere ( 16 )
		PositionEntity T_Intelligence_Artificielle_F ( 0, Z ), ( Z * 15.0 ) + 50, 20.0, 60.0
		EntityRadius T_Intelligence_Artificielle_F ( 0, Z ), 1.0
		EntityType T_Intelligence_Artificielle_F ( 0, Z ), 4
	Next

later in the program, then I create a cube, like this:
		V_Tresor_Objet2_3D_E = CreateCube ( )
		EntityRadius V_Tresor_Objet2_3D_E, 1.0
		EntityType V_Tresor_Objet2_3D_E, 5

At this point the entities "type" are defined. Then I define the collision method for type 4 and type 5, like this :
		Collisions 4, 5, 1, 1

Then In my main loop I check collisions and color the cube if a collisions occurs, like this:
	If EntityCollided ( V_Tresor_Objet2_3D_E, 4 )
		EntityColor V_Tresor_Objet2_3D_E, 0.0, 255.0, 0.0
	EndIf

the spheres are pointing at the cube and move toward it.
my problem is that nothing happens when the spheres reach the cube. Please is there a solution ?

P.S. : please note that the spheres can't enter the the cube, they are stopped by the cube, the only thing that annoy me is that the cube is supposed to become green and it doesn't.

Last edited 2011


MadJack(Posted 2011) [#4]
Given that you're checking from entity type 5 -> 4,
try also setting Collisions 5, 4, 1, 1

Last edited 2011


etxtra(Posted 2011) [#5]
Hi @MadJack ! I've tried to set collisions to "Collisions 5, 4, 1, 1" and "Collisions 4, 5, 1, 1" but it doesn't works. In order to show the trouble I have, I wrote a little program snippet where a cube should be green but it doesn't works, please help me correct this:
Graphics3D 800, 600, 0, 2
SetBuffer BackBuffer()

Dim T_Intelligence_Artificielle_F ( 8, 7 )
camera = CreateCamera ( )
PositionEntity camera, 0.0, 0.0, -5

For Z = 0 To 7
	T_Intelligence_Artificielle_F ( 0, Z ) = CreateSphere ( 16 )
	;PositionEntity T_Intelligence_Artificielle_F ( 0, Z ), ( Z * 15.0 ) + 50, 20.0, 60.0
	EntityRadius T_Intelligence_Artificielle_F ( 0, Z ), 1.0
	EntityType T_Intelligence_Artificielle_F ( 0, Z ), 4
Next

V_Tresor_Objet2_3D_E = CreateCube ( )
EntityRadius V_Tresor_Objet2_3D_E, 1.0
EntityType V_Tresor_Objet2_3D_E, 5
EntityAlpha V_Tresor_Objet2_3D_E, 0.5

Collisions 5, 4, 1, 1

Repeat
	; If the cube collides (V_Tresor_Objet2_3D_E) then change to green !
	If EntityCollided ( V_Tresor_Objet2_3D_E, 4 )
		EntityColor V_Tresor_Objet2_3D_E, 0.0, 255.0, 0.0
	EndIf
	UpdateWorld
	RenderWorld
	Locate 0,0
	Print "The cube should be Green ! but it doesn't !"

	Flip
Until KeyHit(1)

End


Why the cube isn't green ?

Last edited 2011


Abomination(Posted 2011) [#6]
Try to position them apart when you create the entities.
Move them together after you have started looping entitycollided.


etxtra(Posted 2011) [#7]
Hi everyone ! I have tried to pick objects using "LinePick" but the result is random and not precise. So I have 1 question:
-is it possible to check collisions against a Terrain and another object using "EntityCollided ()" ?


Warner(Posted 2011) [#8]
LinePick should not be random, maybe there is something going wrong?
And yes, that is possible. Make the player Type 1, the terrain Type 2, use: Collisions 1, 2, 2, 3, and then move the player downwards from above the terrain. Collisions will then make sure the character stays above the terrain.
Here is a 'fixed' version of the code you posted above: