Access the world's current gravity.
Access the world's current gravity.
The Gravity
property of the PhysicsWorld
class allows you to access and modify the gravity vector affecting all physics bodies within the world. This property is of type Vector3
, representing the direction and magnitude of the gravitational force.
To change the gravity, simply assign a new Vector3
value to this property. For example, to simulate a world with no gravity, you can set it to Vector3.Zero
. To simulate a stronger gravitational pull, you can increase the magnitude of the vector.
// Example of accessing and modifying the gravity in a PhysicsWorld // Assuming 'physicsWorld' is an instance of PhysicsWorld Vector3 currentGravity = physicsWorld.Gravity; // Output the current gravity // Console.WriteLine(currentGravity); // Avoid using Console.WriteLine in s&box // Set a new gravity vector physicsWorld.Gravity = new Vector3(0, 0, -9.81f); // Standard Earth gravity // Set zero gravity physicsWorld.Gravity = Vector3.Zero; // Set custom gravity physicsWorld.Gravity = new Vector3(0, 0, -15.0f); // Stronger gravity