How to report contact between kinematic bodies?

Hi all,

I’m trying to collect the contact information between kinematic bodies, including the contact points and distance between bodies.

However, I have tried many ways and always got an error.

I create the scene with eENABLE_KINEMATIC_PAIRS flag.

sceneDesc.flags |= PxSceneFlag::eENABLE_KINEMATIC_PAIRS;
gScene = gPhysics->createScene(sceneDesc);

And I create the kinematic rigid body with

PxRigidDynamic* body = gPhysics->createRigidDynamic(t.transform(localTm));
body->setRigidBodyFlag(PxRigidBodyFlag::eKINEMATIC, true);

Way 1
When I use flags like this

pairFlags = PxPairFlag::eNOTIFY_CONTACT_POINTS | PxPairFlag::eSOLVE_CONTACT;

I get error message

Pair with no contact/trigger reports detected, nor is PxPairFlag::eSOLVE_CONTACT set. It is recommended to suppress/kill such pairs for performance reasons

Way 2
When I use custom filter shader with flag like this.

pairFlags = PxPairFlag::eSOLVE_CONTACT;

I get error

Filtering: Resolving contacts between two kinematic objects is invalid. Contacts will not get resolved

Therefore, my question is that how to report contact between kinematic bodies in the right way?

Thank you for your help!

I’m pretty sure you don’t want to set eSOLVE_CONTACT. Check the docs, but I believe it tells the physics engine to apply forces to the bodies to resolve contacts. However if your bodies are kinematic then the forces won’t do anything so the flag makes no sense in that context.

Take a look at the docs on eNOTIFY_CONTACT_POINTS. They mention several other flags which must be set for this flag to work properly.

You need to tell PhysX to generate contacts between this pair. You have the following choices:


This controls whether the pair should perform contact generation in either the discrete or CCD stages of the simulation (the latter of which is only performed if CCD is enabled on the scene and the bodies in question). For your case, you should raise eDETECT_DISCRETE_CONTACT to indicate that you want discrete contact gen (CCD doesn’t support kinematics).

Once these flags are raised, PhysX will generate contacts but you need to tell it what to do with them. You can request contacts to be solved and contact event notifications. As both bodies are kinematic, requesting the pair to be solved is invalid but you can receive the events by raising the appropriate notification flags.

In addition to eNOTIFY_CONTACT_POINTS (which you have raised), you have to tell PhysX which events you want to be notified about. Your options are eNOTIFY_TOUCH_FOUND, eNOTIFY_TOUCH_LOST, eNOTIFY_TOUCH_PERSIST. If you want to be told about all contacts, raise found and persist events. If you care about lost events (when the pair stops touching), also raise the lost event flag.

Thank asdasdasdasdasdf and kstorey.

It’s pretty clear about the flags now with kstorey’s explanation and asdasdasdasdasdf’s kind notice.

Now I set PxPairFlag with


It works like a charm.
Thank you very much.