bool Gravity { get; set; }

book_4_sparkGenerated
code_blocksInput

Description

The Gravity property of the Rigidbody class indicates whether gravity is enabled for the rigid body. When set to true, the rigid body will be affected by gravity, causing it to fall or move according to the gravitational force applied in the physics simulation. When set to false, the rigid body will not be influenced by gravity, allowing it to remain stationary or move only under other forces or constraints.

Usage

To enable or disable gravity for a Rigidbody instance, simply set the Gravity property to true or false respectively. This can be useful for simulating objects in space or for specific gameplay mechanics where gravity should not affect certain objects.

Example

// Example of toggling gravity on a Rigidbody
Rigidbody myRigidbody = new Rigidbody();

// Enable gravity
myRigidbody.Gravity = true;

// Disable gravity
myRigidbody.Gravity = false;