🤔 Unity, huh, how?

🤔

Quaternion.AngleAxis

Declaration

public static Quaternion AngleAxis(float angle, Vector3 axis);

Description

Creates a rotation which rotates angle degrees around axis.
Euler angles are confusing to author when rotating off-axis. AngleAxis greatly simplifies this.

transform.rotation = Quaternion.AngleAxis(30, Vector3.up);
// Is the same as:
transform.rotation = Quaternion.Euler(new Vector3(0, 30, 0));

Interactive diagram

Drag the sphere to modify axis, move the slider to change angle.

Vector3 axis = new Vector3(0, 1, 0);
transform.rotation = Quaternion.AngleAxis(30, axis);

Note that the rotation angle is scalar, it does not start at the visualised position.


Return to Quaternions.
Next, Quaternion.LookRotation.