NVIDIA-Omniverse / PhysX

NVIDIA PhysX SDK
BSD 3-Clause "New" or "Revised" License
2.54k stars 361 forks source link

Trigger emulation and character controller #259

Closed karjonas closed 6 months ago

karjonas commented 6 months ago

Library and Version

PhysX v5.3.1

Operating System

Linux

Steps to Trigger Behavior

It is suggested in the documentation that you can emulate trigger bodies using shader filters (https://nvidia-omniverse.github.io/PhysX/physx/5.3.1/docs/AdvancedCollisionDetection.html#triggers). However, these do not seem to work with character controllers. Is this expect or a bug? I have modified the SnippetTriggers snippet to use a character controller instead. I have attached a patch file for the SnippetTriggers you can apply to try it out.

fallingchar.txt

PierreTerdiman commented 6 months ago

Character controllers use kinematic actors and scene-queries, so there are some changes needed in the snippet to be compatible with that system.

a) tell PhysX to keep interactions between kinematic and static actors when creating the scene:

sceneDesc.staticKineFilteringMode = PxPairFilteringMode::eKEEP;

Without this, the overlaps between static & kinematic actors are discarded by the broadphase, and the filter shader emulating the trigger behavior is never called (the character controller silently goes through the trigger).

b) disable scene-queries on trigger shapes in the "filter callback" case:

    else if(impl==FILTER_CALLBACK)
    {
        PxShapeFlags shapeFlags = PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSIMULATION_SHAPE;
        // We will have access to shape pointers in the filter callback so we just mark triggers in an arbitrary way here,
        // for example using the shape's userData.
        shape = gPhysics->createShape(geom, *gMaterial, isExclusive, shapeFlags);
        shape->userData = shape;    // Arbitrary rule: it's a trigger if non null
    }

Without this, the character controller's shape registers an impact against the trigger, and the chatacter stops against the trigger. This is only needed in the "filter callback" codepath:


After these two changes, the snippet should work with character controllers.

karjonas commented 6 months ago

Thanks for the information

PierreTerdiman commented 6 months ago

Closing for now, please re-open if needed.