How to activate bodies from a step listener? #784
-
I'm using a step listener to implement game object movement. I've been seeing a bug where when an object is initially touched by something else it can shoot off at high velocity. Just today I had the thought that that is probably caused by the bodies being asleep while accumulating velocity from repeated impulse applying. But I ran into a major issue: I apply the impulse with a step listener and I can't figure out how to activate the body without this assert triggering: This is the code I tried: physicsSystem->GetBodyInterfaceNoLock().ActivateBody(bodyId); I've already been using the no-lock interface for setting the body velocity and angular velocity, which seems to work fine. But that above code causes an assert to trigger within like a second of things starting to happen. I tried the locking variant but that just permanently locks up the entire process: physicsSystem->GetBodyInterface().ActivateBody(bodyId); Is there a correct way to activate bodies from a step listener that I missed? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The assert If you want a body to wake up when applying an impulse you need to call |
Beta Was this translation helpful? Give feedback.
The assert
JPH_ASSERT(body.IsInBroadPhase());
means that you're trying to activate a body that hasn't been added to thePhysicsSystem
(usingBodyInterface::AddBody
).If you want a body to wake up when applying an impulse you need to call
BodyInterface::AddImpulse
instead ofBody::AddImpulse
. Otherwise you can indeed start accumulating velocity on a sleeping body (and if the body hasn't been added to the world it's the same thing). I'll have to add an assert there.