Rotation
Summary
Represents a rotation or orientation in 3D space. See https://docs.unity3d.com/ScriptReference/Quaternion.html for further documentation
Class Properties
Name | Return Type | Description |
---|---|---|
zero | Rotation Read-only | A rotation of zero in all axes |
left | Rotation Read-only | A 90 degree anti-clockwise rotation in the y axis (yaw) |
right | Rotation Read-only | A 90 degree clockwise rotation in the y axis (yaw) |
up | Rotation Read-only | A 90 degree clockwise rotation in the x axis (pitch) |
down | Rotation Read-only | A 90 degree anti-clockwise rotation in the x axis (pitch) |
Instance Properties
Name | Return Type | Description |
---|---|---|
this[index] | number Read/Write | The amount of rotation in degrees around a single axis (0=x, 1=y, 2=z) |
x | number Read/Write | The amount of rotation around the x axis in degrees |
y | number Read/Write | The amount of rotation around the y axis in degrees |
z | number Read/Write | The amount of rotation around the z axis in degrees |
normalized | Rotation Read-only | Converts this rotation to one with the same orientation but with a magnitude of 1 |
inverse | Rotation Read-only | Returns the Inverse of this rotation |
angle | number Read/Write | The angle in degrees of the angle-axis representation of this rotation |
axis | Vector3 Read/Write | The axis part of the angle-axis representation of this rotation |
Class Methods
Rotation:New(x, y, z)
Creates a new Rotation
Returns: Rotation
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x | number | 0 | The angle of rotation on the x axis in degrees |
y | number | 0 | The angle of rotation on the y axis in degrees |
z | number | 0 | The angle of rotation on the z axis in degrees |
Example
Rotation:Angle(a, b)
Returns the angle in degrees between two rotations
Returns: number (Returns the angle in degrees between two rotations)
Parameters:
Example
Rotation:AngleAxis(angle, axis)
Creates a rotation which rotates angle degrees around axis
Returns: Rotation (Returns a Quaternion that represents the rotation)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
angle | number | The angle in degrees | |
axis | The axis of rotation |
Example
Rotation:Dot(a, b)
The dot product between two rotations
Returns: number (Returns the dot product between two rotations)
Parameters:
Example
Rotation:FromToRotation(from, to)
Creates a rotation which rotates from fromDirection to toDirection
Returns: Rotation (Returns a Quaternion that represents the rotation)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
from | The initial direction vector | ||
to | The target direction vector |
Example
Rotation:Lerp(a, b, t)
Interpolates between a and b by t and normalizes the result afterwards. The parameter t is clamped to the range [0, 1]
Returns: Rotation (Interpolated rotation)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
a | The first rotation | ||
b | The second rotation | ||
t | number | A ratio between 0 and 1 |
Example
Rotation:LerpUnclamped(a, b, t)
Interpolates between a and b by t and normalizes the result afterwards. The parameter t is not clamped
Returns: Rotation (Interpolated rotation)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
a | The first rotation | ||
b | The second rotation | ||
t | number | A ratio between 0 and 1 |
Example
Rotation:LookRotation(forward)
Creates a rotation with the specified forward and upwards directions
Returns: Rotation (Rotation with specified forward direction)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
forward | Vector3 forward direction |
Example
Rotation:LookRotation(forward, up)
Creates a rotation with the specified forward and upwards directions
Returns: Rotation (Rotation with specified forward and up directions)
Parameters:
Example
Rotation:Normalize(a)
Converts this quaternion to one with the same orientation but with a magnitude of 1
Returns: Rotation (Normalized rotation)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
a | The input rotation |
Example
Rotation:RotateTowards(from, to, maxDegreesDelta)
Rotates a rotation from towards to
Returns: Rotation (Rotation rotated from towards to)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
from | Rotation from | ||
to | Rotation to | ||
maxDegreesDelta | number | Max degrees delta |
Example
Rotation:Slerp(a, b, t)
Spherically interpolates between quaternions a and b by ratio t. The parameter t is clamped to the range [0, 1]
Returns: Rotation (Spherically interpolated rotation)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
a | The first rotation | ||
b | The second rotation | ||
t | number | A ratio between 0 and 1 |
Example
Rotation:SlerpUnclamped(a, b, t)
Spherically interpolates between a and b by t. The parameter t is not clamped
Returns: Rotation (Spherically interpolated rotation)
Parameters:
Example
Instance Methods
rotation:SetFromToRotation(fromDirection, toDirection)
Creates a rotation which rotates from one direction to another
Returns: Rotation (A rotation that would change one direction to the other)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
fromDirection | The starting direction | ||
toDirection | The target direction |
Example
rotation:SetLookRotation(view)
Creates a rotation with the specified forward directions
Returns: Rotation (The new Rotation)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
view | The direction to look in |
Example
rotation:SetLookRotation(view, up)
Creates a rotation with the specified forward and upwards directions
Returns: Rotation (The new Rotation)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
view | The direction to look in | ||
up | The vector that defines in which direction is up |
Example
rotation:Multiply(other)
Combines two rotations
Returns: Rotation (The rotation that represents applying both rotations in turn)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
other | The other rotation |
Example
rotation:NotEquals(other)
Determines whether this rotation is not equal to the specified rotation
Returns: boolean (true if this rotation is not equal to the specified rotation; otherwise, false)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
other | The rotation to compare |
Example
Last updated