VulCode

Unity rotation: Euler and Quaternion

Convert Euler angles to a Quaternion and back the way Unity does, with C#.

Category
SCP:SL, Steam and Unity
Price
free

The tool starts in your browser.

Everything is calculated in your browser. Nothing you type is sent to our server.

How to use it in three steps

The tool as a schematic with this page's example. Each step's number stands where you take it: in the fields, at the result or outside the tool.

Unity rotation: Euler and Quaternion
What you enter
Euler: 0, 90, 0
  1. Enter Euler angles or quaternion components.

What you get
new Quaternion(0f, 0.7071f, 0f, 0.7071f) transform.forward (1, 0, 0)
  1. See the other form and an axis preview.

  2. Copy the ready C# line.

A 90 degree turn around Y as a quaternion

Unity stores a rotation as a quaternion and shows Euler angles in the inspector. The tool computes one from the other in Unity's axis order. The result is computed by the same function the tool at the top of the page uses, every time the page is shown.

Euler angles

X
0 degrees
Y
90 degrees
Z
0 degrees

Half the angle

cos 45
0.7071
sin 45
0.7071
What the tool does

A quaternion takes the sine and cosine of half the angle: 90 degrees gives 45.

Quaternion

new Quaternion
new Quaternion(0f, 0.7071f, 0f, 0.7071f)
What the tool does

A turn around Y alone leaves the y and w components, with x and z at zero.

The object's directions

transform.forward
(1, 0, 0)
transform.right
(0, 0, -1)
What the tool does

The forward and right vectors after the turn show where the object faces.

C#

  • Quaternion.Euler(0f, 90f, 0f)
  • new Quaternion(0f, 0.7071f, 0f, 0.7071f)
  • new Vector3(0f, 90f, 0f)

Questions