At a certain point in my game I need to reposition nodes that have rigidbody physics attached to them. When I use SetRotation the physics engine kicks in causes the nodes interact with other components in the scene. I would like to temporarily suspend the physics engine while I reposition the nodes and then turn it back on again. Any suggestions on how to do this?
Archive 19/01/2023.
Pause physics while re-positioning nodes
capelenglish
guk_alex
Very easy. You can disable whole physics world or only certain components.
To disable whole physics world use:
auto* physicsWorld = node_->GetScene()->GetComponent<PhysicsWorld>();
physicsWorld->SetUpdateEnabled(false);
To disable physics of one object use:
auto* rigidBody = object->GetNode()->GetComponent<RigidBody>();
rigidBody->SetEnabled(false);
To enable it again set ‘true’ in these functions.
guk_alex
Also, you can stop the time.
Scene* scene = node_->GetScene();
scene->SetTimeScale(0.f);
capelenglish
Thanks, this is just what I was looking for.
Modanung
Instead of
Scene::SetTimeScale(float)
you could also use
Scene::SetUpdateEnabled(bool)
.