kinematic > static collision detection

damiench
Posts: 14
Joined: Thu Feb 18, 2010 4:10 pm

kinematic > static collision detection

Post by damiench »

Hi,

I have a dynamic world with both kinematic and static objects.
I simply want to detect collision between the kinematic objects and the static objects.

It seems very simple but I cannot not make it work.

If I want to use kinematic object I have to setActivationState to DISABLE_DEACTIVATION, do this feature make collision detection not work? If I don't my kinematic objects are not update by their motionstate... :(

Also, I cannot use performDiscreteCollisionDetection because it doesn't call motionstate to update for kinematic objects.

A clue?

Thank you
User avatar
LangFox
Posts: 4
Joined: Tue Dec 29, 2009 2:07 pm

Re: kinematic > static collision detection

Post by LangFox »

try this(from the manual):

Code: Select all

btRigidBody* body = new btRigidBody(cInfo);
body->setCollisionFlags( body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); 
body->setActivationState(DISABLE_DEACTIVATION);
damiench
Posts: 14
Joined: Thu Feb 18, 2010 4:10 pm

Re: kinematic > static collision detection

Post by damiench »

Hi,

Pieces of code you suggest me is already in my code for kinematic object.
It is not working.

My problem is not to set an object as kinematic.
I already set:
static objects (zero mass, flag to btCollisionObject::CF_STATIC_OBJECT)
kinematic objects (zero mass, flag to btCollisionObject::CF_KINEMATIC_OBJECT and activation state to DISABLE_DEACTIVATION).

My problem is how to detect kinematic / static collision.

For example when a character (kinematic) go through some volume in the scene (static).
Can Bullet detect such collision?

I could stick to a btCollisionWorld (but not sure it will works) but I would rather use btDynamicWorld to keep the motionstate feature.

I tried body->forceActivationState(ACTIVE_TAG);
Didn't work.

The problem with using only performDiscreteCollisionDetection() is that kinematic motionState are not update even if I call synchronizeMotionStates() (which ignore kinematic objects). Didn't work too.

Any clues?
damiench
Posts: 14
Joined: Thu Feb 18, 2010 4:10 pm

Re: kinematic > static collision detection

Post by damiench »

Ok,

The best thing I found to do what I wanted was the following.

I simply want to detect collision between a moving avatar and some geometry in my scene.

What I did was:
-avatar > set as a kinematic object (with specific motionstate), mass = 0, collision flag = CF_KINEMATIC_OBJECT and activation state = DISABLE_DEACTIVATION

-scene > set to dynamic but with mass = 0 and collision flag = CF_NO_CONTACT_RESPONSE

If I put the scene in static, no collisions are detected. I guess this is because it is filtered at an early stage by the broadphase. Could some experts confirm this?


I wanted then to add some collision filtering (as in chap 5 of the sdk manual):
I don't need to detect collision between objects of my scene so for the rigid body of the scene I did:
world->addRigidBody(body, COLL_SCENE, COLL_AVATAR);

Avatar don't collide with anything so it should be something like:
world->addRigidBody(body, COLL_AVATAR, COLL_NOTHING);

But it didn't work (no collision detected) so I put:
world->addRigidBody(body, COLL_AVATAR, COLL_SCENE);

I am surprised, is this normal? Is this a bug?

Thank you
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: kinematic > static collision detection

Post by Flix »

damiench wrote:For example when a character (kinematic) go through some volume in the scene (static).
Can Bullet detect such collision?
Kinematic bodies can't collide with static bodies in Bullet: that's one reason why a (kinematic) character controller must be used in this situation. There's a demo about it.

There are altenative ways to perform this kind of collision (kinematic vs static), but are a bit complicated: adding a ghost object manually is one option (actually it's the same used by the character controller internally), or performing a collision test query using a body created on the fly (and not added to the world) in the same position of one of the two static bodies and processing the manifold for collisions with the other body.

I guess using the character controller is the simpler way. Usually I use kinematic objects only for some very specific purposes: when possible I replace them with dynamic bodies and move them by setting their velocity (there are some transform utils that can be handy) and/or using constraints.

Hope it helps.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: kinematic > static collision detection

Post by Erwin Coumans »

You can also try using the btCollisionWorld::contactTest or btCollisionWorld::contactPairTest, new in Bullet 2.76.

Thanks,
Erwin