Topic was automatically imported from the old Question2Answer platform.
Asked By
brylie
I have a scene with several bowling balls that fall when the game starts. I would like to add a button that enables physics when clicked, so that the balls do not fall until the button is pressed. How can I turn physics on and off from GDScript?
If the balls you use are RigidBodies, you can use set_use_custom_integrator(). All rigid bodies have this method to turn on, or turn off, the integration of forces (like gravity) performed by Godot.
When you set set_use_custom_integrator(false), Godot performs integrations of forces to compute the new speed and position of the body (This is the default behavior). When you set set_use_custom_integrator(true), Godot doesn’t integrate forces itself. That is, it ignores every forces including gravity. But you can still use the method func _integrate_forces( body_state ) to define any physic calculations yourself.
So in your case, I guess you could program your button so every bowling balls of your scene toogle their custom integrator to true or false. I suppose it won’t represent much code if your button sends signals and if your bowling balls have the same script.
You may also want to immobilize your bodies once the custom integrator is used :