kinematic controllers with compound shapes

nokto
Posts: 8
Joined: Fri Apr 17, 2009 12:04 am

kinematic controllers with compound shapes

Post by nokto »

Hi everyone,

I have been working on Bullet for a few days and I got stucked with something strange.

As far as know, kinematic controllers are meant to move user controlled collision objects, such as players, enemies or moving platforms. I'm working on a game where I need to move, rotate and do different things with an L-shaped platform, so I thought I could use this feature. So I did a compound shape with 2 boxes as children, so I could archieve my goal easily, and I proceeded as following:

Code: Select all

btCompoundShape *colSha;
//do stuff with colSha
btTransform t;
t.setFromOpenGLMatrix(...);	
btPairCachingGhostObject* ghostObject = new btPairCachingGhostObject();
ghostObject->setWorldTransform(t);
ghostObject->setCollisionShape (colSha);
ghostObject->setCollisionFlags (btCollisionObject::CF_KINEMATIC_OBJECT);
btKinematicCharacterController* controller = new btKinematicCharacterController (ghostObject,colSha,0.f);
I found myself with an error initializing controller:

Code: Select all

btKinematicCharacterController (btPairCachingGhostObject* ghostObject,btConvexShape* convexShape,btScalar stepHeight, int upAxis = 1);
btCollisionShape is not a convex shape, nor inherits from it. Does that mean I can't control, as user, convex-shaped kinematic bodies? If so, is there a reason for it? Is there any other possible way of doing what I'm trying to do?

Many thanks in advance,
nokto.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: kinematic controllers with compound shapes

Post by Erwin Coumans »

For kinematic bodies you don't need a character controller, just flag a static rigid body (mass=0) with the kinematic flag. Then, you can use a concave collision shape.

Code: Select all

body->setCollisionFlags( body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
//DISABLE_DEACTIVATION  is optional, but usual preferable for kinematic objects, as long as they are moving
body->setActivationState(DISABLE_DEACTIVATION);
Hope this helps,
Erwin
nokto
Posts: 8
Joined: Fri Apr 17, 2009 12:04 am

Re: kinematic controllers with compound shapes

Post by nokto »

Thank you very much for the fast feedback. The problem is solved and it saved my life today.

nokto.