Description
The LocalRotation
property of a GameObject
represents the rotation of the object relative to its parent. This property is crucial for determining the orientation of the object within its local coordinate space, which is particularly useful when the object is part of a hierarchy of objects.
Usage
To access or modify the local rotation of a GameObject
, you can use the LocalRotation
property. This property is of type Rotation
, which allows you to set or get the rotation in a way that is consistent with the object's local coordinate system.
For example, you might want to rotate an object around its local Y-axis by a certain angle. You can achieve this by modifying the LocalRotation
property directly.
Example
// Example of setting the local rotation of a GameObject
GameObject myObject = new GameObject();
myObject.LocalRotation = Rotation.FromAxis(Vector3.Up, 45.0f); // Rotates the object 45 degrees around the local Y-axis
// Example of getting the local rotation of a GameObject
Rotation currentRotation = myObject.LocalRotation;
Vector3 eulerAngles = currentRotation.Angles();
// Output the current local rotation in Euler angles
// Note: Avoid using Console.WriteLine in Sandbox environment
// Instead, use logging or debugging tools provided by the environment
Log.Info($"Current Local Rotation: {eulerAngles}");