Description
The Rotation.LookAt
method creates a Rotation
that aligns the forward direction with a specified target direction, using an additional up vector to determine the orientation around the forward axis. This method is useful for orienting objects to face a specific direction in 3D space.
Usage
To use the Rotation.LookAt
method, provide two Vector3
parameters:
forward
: The target direction that the forward vector should point towards.
up
: The world up direction, which helps to define the orientation around the forward vector.
The method returns a Rotation
object that represents the orientation needed to face the target direction.
Example
// Example usage of Rotation.LookAt
Vector3 targetDirection = new Vector3(1, 0, 0); // Target direction
Vector3 worldUp = new Vector3(0, 1, 0); // World up direction
// Create a rotation that looks towards the target direction
Rotation lookAtRotation = Rotation.LookAt(targetDirection, worldUp);
// Apply this rotation to an object
GameObject myObject = new GameObject();
myObject.Transform.Rotation = lookAtRotation;