How to manage multiple Character Controllers ?

User avatar
cippyboy
Posts: 36
Joined: Fri Aug 25, 2006 1:00 am
Location: Bucharest

How to manage multiple Character Controllers ?

Post by cippyboy »

The question is simple, how to manager collisions between multiple Character Controllers ? I've implemented a btKinematicCharacterController, it works right but now I want to add multiple characters to my scene, player controlled + AI and they can go through each other. I'm not certain where I should place my collision callbacks as it seems they don't even register.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: How to manage multiple Character Controllers ?

Post by Flix »

I suppose the best way to handle collisions between multiple characters, provided that they can collide with each other (i.e. filters allow it), but they have no collision response (CF_NO_COLLISION_RESPONSE), is to customize the KinematicCharacterController's recoverFromPenetration method (please read further).

By changing the collision flags of the btGhostObjects inside btKinematicCharacterControllers it's also possible to make them collide with each other WITHOUT tweaking the recoverFromPenetration method: the drawback is that by doing so, the btKinematicCharacterControllers can be easily pushed out of any btBvhTriangleMeshShape used as background (BTW: the original Bullet's CharacterDemo uses "maps" as static btConvexHullShapes, so it should not suffer from this isssue :) (*) ).

To change the collision flags of the btGhostObjects inside btKinematicCharacterControllers, you can do:

Code: Select all

myCharacter->getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup = btBroadphaseProxy::CharacterFilter  | btBroadphaseProxy::StaticFilter | btBroadphaseProxy::KinematicFilter;//btBroadphaseProxy::KinematicFilter is optional
myCharacter->getGhostObject()->getBroadphaseHandle()->m_collisionFilterMask = btBroadphaseProxy::AllFilter;
Additionally you can probably use:

Code: Select all

myCharacter->getGhostObject()->setCollisionFlags(CF_NO_COLLISION_RESPONSE);
if you want to override the recoverFromPenetration (character won't collide, but their collision data should be available).

(*) As I've already written in another post, by using <BulletCollision/Gimpact/btCompoundFromGimpact.h> it's possible to turn a btStridingMeshInterface into a series of tetrahedrons (unwrapping the resulting compound shape is highly recommended). [Edit:] I've found a workaround to this problem that works for me. Please see http://www.bulletphysics.org/Bullet/php ... 768#p32768.

As I've already written in other posts, I'm not very familiar with the btKinematicCharacterController (I've just used it in a single demo without any modifications), and its Bullet implementation has been declared incomplete AFAIR: so if you really want to use it you know what you're facing :P.
Last edited by Flix on Fri Jan 31, 2014 12:41 pm, edited 1 time in total.
User avatar
cippyboy
Posts: 36
Joined: Fri Aug 25, 2006 1:00 am
Location: Bucharest

Re: How to manage multiple Character Controllers ?

Post by cippyboy »

EDIT :

Thanks for the reply, I just tried putting the filters you talked about and it works but I had a rather weird error in the code. I was setting up a tranform matrix but never set up the rotation part, so because of that the rotation part was getting into some nasty NANs and were killing my framerate while collisions didn't work either ! I have to remember I always need to call setIdentity after I declare a transform, that fixed it.