Unity Directions

In by John FrenchPublished

A normalised vector, or Unit Vector, is a vector that only describes a direction and always has a length of 1. For example the unit vector (0,0,1) describes the forward direction in world space, while (0,0,-1) would be backwards.

In Unity, you’ll find shorthand expressions for common directional vectors in the Vector 3 class.

For example:

Vector3.forward   // (0,  0,  1)
Vector3.back      // (0,  0,  -1)
Vector3.up        // (0,  1,  0)
Vector3.down      // (0,  -1, 0)
Vector3.right     // (1,  0,  0)
Vector3.left      // (-1, 0,  0)

These relate to basic directions in world space and are typically easier to use than creating a new Vector 3.

While the transform component also provides a number of direction vectors for forward, up and right.

While their opposites, the negative values of their directions, can be used to create directional vectors for back, down and left.

Like this:

transform.forward  // object forward
-transform.forward // object back
transform.up       // object up
-transform.up      // object down
transform.right    // object right
-transform.right   // object left

These relate to the local orientation of the object’s transform, and can be useful for getting an object’s forward direction, for example.

These ready-made directions can be extremely useful for creating object-relative movement.

Like this:

transform.position += transform.forward * speed * Time.deltaTime;

See Also