Sign in to follow this  
all_names_taken

Bullet - detecting collisions with character controller

Recommended Posts

Using the Bullet Physics API for simulation, how can collisions with a character controller be detected by the user (me)? In particular, whenever a dynamic body collides with the character, I'd like to know which body it was, and its velocity at the time of collision. Looking at the interfaces of btKinematicCharacterController and btGhostShape they don't seem to have any member functions or callbacks relevant to this, or maybe I'm missing something?

Share this post


Link to post
Share on other sites
Ok, I'm now using the callback to be able to perform queries and processing between each internal tick. However, I'm still out of ideas on where to obtain the velocity of objects that collided?

Where, to begin with, can I obtain the overlapping object pairs? Only thing I can find is the btBroadphaseInterface (that I sent to the world when constructing it) from which I can get the btOverlappingPairCache, then call:
btOverlappingPairCache::processAllOverlappingPairs (btOverlapCallback *, btDispatcher *dispatcher)

And search for a pair in which one of the objects is a character controller. But that's for broad-phase overlapping object pairs. If I use that I'd need to manually narrow-phase collision test the pair before I can determine whether it'll be a hit or not. This seems wasteful and redundant because bullet must surely do this collision test itself internally once during each simulation tick. Is there no way of obtaining the "narrow-phrase overlapping pairs" directly?

Share this post


Link to post
Share on other sites
btDynamicsWorld->getDispatcher()->getNumManifolds() will get you the number of overlapping bodies in this tick. Do a for loop through those and then get btDynamicsWorld->getDispatcher()->getManifoldByIndexInternal() which will get you the manifold where you can get the rigid body for each and through the user pointer you can figure out which entity type each body is. Then from the manifold you can get all the contact points which give you the info like collision strength. Though most times there is no meaningfil contact point data until a collision has been around a frame.

Share this post


Link to post
Share on other sites
Thank you, this worked. But are users really supposed to use the method getManifoldByIndexInternal(), it sounds like a method for internal use by the API? Well I can't find any alternative method in the dispatcher...

Or is the intended use to inherit from btCollisioDispatcher or some other class to add own processing by overriding one of the interface methods?

Share this post


Link to post
Share on other sites
To be honest, I don't know. But I have seen getManifoldByIndexInternal() in every piece of code dealing with the tick callback that I assume its the correct way of processing. Its the method used in Game Coding Complete 3rd edition so I wouldn't think it would be done wrong in that book. I think its just a badly named function.

Share this post


Link to post
Share on other sites
Ok, fair enough!

I see it's used in the bullet wiki too:
http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Callbacks_and_Triggers

This text is interesting though:
http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Filtering

This:
"Your spaceship needs a callback when it collides with a wall [for example, to produce a “plink” sound], but the walls do nothing when you collide with them so they do not need to receive callbacks. "
And:

enum collisiontypes {
COL_NOTHING = 0, //<Collide with nothing
COL_SHIP = BIT(1), //<Collide with ships
COL_WALL = BIT(2), //<Collide with walls
COL_POWERUP = BIT(3) //<Collide with powerups
}
...
int wallCollidesWith = COL_NOTHING;
int shipCollidesWith = COL_WALL;
...
mWorld->addRigidBody(wall, COL_WALL, wallCollidesWith);
mWorld->addRigidBody(ship, COL_SHIP, shipCollidesWith);


What callbacks are they referring to in that article?

This mention of callbacks seems strange also because I always thought the collision masks were used for determining whether objects collided, not for deciding whether you wanted a callback, so the powerup colliding with the ship would mean the powerup bouncing away when the ship hits it???

Share this post


Link to post
Share on other sites
There are some other callbacks that can be set with Bullet like gContactAddedCallback and I think its refering to them. Because even bodies that have collision filtering should generate manifolds in the tick callback. Its just Bullet doesn't do any physical modelling of the collision.

That wiki article is over a year old now and I think before you were supposed to use the global contacts but since then its shifted more towards using the tick callback. Bullet documentation is pretty bad and out of date. Most of my questions were only answered by searching forum posts. Its like pulling teeth to get any questions answered today. Then the physics code in Game Coding Complete showed a fairly decent skeleton to handling collisions. The code is a free download on the book website.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this