I have an example project set up that does the following:
- Creates two kinematic trigger boxes that aren't touching.
- Creates a capsule inside box A.
- Moves the capsule to box B using setKinematicTarget().
- Runs simulate(1.f) and fetchResults(true) on the scene.
I noticed that even though the active transforms for that simulation step includes the capsule’s movement to the second box, there are no trigger events coming in, and I have to run simulate/fetchResults a second time in order to receive them.
This page mentions that when we receive onTrigger/onContact events, it’s before the buffer swap and that the objects will be in the position that they were before the simulation ran. Does this also mean that trigger events are essentially delayed one simulation step since they need to have “made contact” before the buffer swap or simulation? Or is there something else at play that I’m missing?
Edit: Just for the sake of completeness, here’s some snippets of code in case I’m doing something obviously wrong.
boxPosition.x = 20.f; // Create box at boxPosition boxBody->setRigidDynamicFlag(physx::PxRigidDynamicFlag::eKINEMATIC, true); boxBody->getShapes(&boxShape, 1); boxShape->setFlag(physx::PxShapeFlag::eSIMULATION_SHAPE, false); boxShape->setFlag(physx::PxShapeFlag::eTRIGGER_SHAPE, true); scene->addActor(*boxBody); boxPosition.x = -20.f; // Repeat above block for boxBodyB ... // Create capsule at boxBody->getGlobalPose() capsuleBody->setRigidDynamicFlag(physx::PxRigidDynamicFlag::eKINEMATIC, true); scene->addActor(*capsuleBody); ... capsuleBody->setKinematicTarget(boxBodyB->getGlobalPose()); scene->simulate(1.f); scene->fetchResults(true); // We only get the "entered box A" event here. scene->simulate(1.f); scene->fetchResults(true); // We get "exited box A" and "entered box B" here.
I confirmed with the visual debugger that the proper movement is taking place, but it also seems one frame behind.