开发者

box2d, is it possible to freeze a body?

开发者 https://www.devze.com 2023-02-19 05:29 出处:网络
Hey, im wondering if its possible to freeze a body from the bodyList(), then unfreeze it. The unfreeze should retain all its inertias, so that they continue along their paths if as if they where never

Hey, im wondering if its possible to freeze a body from the bodyList(), then unfreeze it. The unfreeze should retain all its inertias, so that they continue along their paths if as if they where never frozen...

Basically Im using the b->SetType(b2_staticBody) and b->SetType(b2_dynamicBody).

But this creates a huge problem because it resets all the original inertia values.

Thousa开发者_如何学Gond Thankyous,

Oliver.


I can't test this right now, but have you tried

b->SetActive(false); //freeze
b->SetActive(true); //unfreeze

I think it will freeze things in place, but I am unsure if it retains the intertia. The documentation says that inactive bodies are not simulated, so I would expect them to just sit there until active again.


Possibly you could set your body untouchable specifying it's b2Filter. So it will not collide with any other bodies. And also apply a force equal to gravity - so it will stay where you want.

But i think the right way will be to set it's type to static and preserve it's inertia parameters to restore them later

0

精彩评论

暂无评论...
验证码 换一张
取 消