PhysicsLock Locking { get; set; }

book_4_sparkGenerated
code_blocksInput

Description

The Locking property of the Rigidbody class is used to control the locking state of the rigidbody in the physics simulation. It determines which axes of the rigidbody are locked, preventing movement or rotation along those axes. This can be useful for simulating objects that should only move or rotate in specific ways, such as a door that only rotates around its hinges.

Usage

To use the Locking property, you can set it to a value of type PhysicsLock, which specifies the axes to lock. This property is not static, so it must be accessed through an instance of the Rigidbody class.

Example

// Example of setting the Locking property on a Rigidbody instance
Rigidbody myRigidbody = new Rigidbody();

// Lock the rigidbody's movement along the X and Y axes
myRigidbody.Locking = PhysicsLock.PositionX | PhysicsLock.PositionY;

// Lock the rigidbody's rotation around the Z axis
myRigidbody.Locking |= PhysicsLock.RotationZ;