Collisions

Blitz3D Forums/Blitz3D Beginners Area/Collisions

Gazza69(Posted 2012) [#1]
Bit confused with collisions. I have the basics down pat with 1 object hitting another, but when a few objects are involved, I'm a little lost.
An example:

Say I have 2 spheres parented to a pivot, and I use this pivot to control the movement of the spheres. I set the spheres to the same collision type (e.g. 1) using EntityType. The spheres are some distance apart. I then make a cube and set that to type 2
Then I set up collisions like :
Const SPHERE=1, CUBE=2
Collisions SPHERE,CUBE,3,1

Then test for a collision
If EntityCollided(sphere,CUBE) Then
Text 370,80,"Collided !!!"
EndIf

Question is : Do I need to check for each sphere (say I have sphere1 and sphere2) to collide with the cube, or is there a better way of doing this ? If 1 sphere hits the cube, it should stop given the collision rule above, but that won't stop the the pivot or other sphere ? Or do I have to check entitycollided for all objects that are connected to the pivot, and the pivot ?
I'm probably showing my noobness here a bit, but having fun nonetheless.

Q2. When do I know what type of collision detection to use ?

1 = Sphere-to-Sphere
2 = Sphere-to-Polygon
3 = Sphere-to-Box

Does it depend on the object type ?
Ok thats enough rambling


PowerPC603(Posted 2012) [#2]
You can also do it the other way around.
Keep the setup as you already have (sphere collides with cube), but check the cube for any collisions instead of the spheres.

If the cube has more than 1 collision, you can retrieve the data from it.
This will give you the actual sphere that collided with it.
Then you can grab the parent of that sphere. In your case, the pivot.

Then you can do whatever you want with it, like setting a variable to keep your code from moving the pivot any further.


RemiD(Posted 2012) [#3]
To move the characters on the map so that they don't go through others characters or through walls, i use :
Moving collider sphere vs moving collider sphere, response slide :
Collisions(ColliderSphere1,ColliderSphere2,1,2)
and
Moving collider sphere vs static collider mesh, response slide :
Collisions(ColliderSphere1,ColliderMesh,2,2)

To know when a projectile or a weapon hits a character or another weapon, i use :
Moving collider sphere vs moving collider sphere, response stop :
Collisions(ColliderSphere1,ColliderSphere2,1,1)
and
Moving collider sphere vs static collider mesh, response stop :
Collisions(ColliderSphere1,ColliderMesh,2,1)

If you want to use several colliders spheres as a "hull" for a character or a vehicle, i suggest to use a collision response stop and with the help of TFormPoint() and TFormVector() you can reposition your entity at the wanted position.

Also you don't need to check the collisions a collider has had each frame, only when you need it. (in order to retrieve the other collider pointer, the collision point coordinates, the collision normal properties)

Last edited 2012