Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 38 ยท Actors and Components

Unreal Vectors, Rotators and Transforms: The Math You Need

Learn the math behind Unreal gameplay: vectors, dot and cross product, normalizing, distance, rotators versus quaternions, lerp and transforms, with runnable examples.

Almost every gameplay task is vector math in disguise: move toward a target, check if an enemy is in front of you, rotate a turret, blend between two positions. Unreal gives you the types Vector, Rotator, Quaternion and Transform and plenty of nodes (and C++ functions) for them. This lesson explains the ideas, so the nodes make sense when you meet them.

The math below is plain Python, which runs on this page. In Unreal the same operations are nodes such as Vector Length, Normalize, Dot Product and Find Look at Rotation.

Vectors

A Vector (FVector) has X, Y and Z values. It can mean a position (a point) or a direction with a length (for example velocity). Basic operations:

  • Add / subtract: target - start gives the vector from start to target.
  • Length (magnitude): the distance. Distance(A, B) is Length(B - A).
  • Normalize: scale a vector to length 1, keeping its direction (a unit vector).
  • Multiply by a number: scales its length. direction * speed * deltaSeconds is one step of movement.
Python Stand-in: moving toward a target

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The loop is exactly what a "move to location" or Move Component To does.

Dot product: how aligned are two directions?

For two unit vectors the dot product is a number from -1 to 1:

  • 1: they point the same way.
  • 0: they are perpendicular (90 degrees).
  • -1: opposite.

To test whether an enemy is in front of the player, take the dot product of the player's forward vector with the normalized direction to the enemy; if it is above, say, 0.5, the enemy is within about 60 degrees of the center of view.

Cross product: a vector perpendicular to two others

The cross product returns a vector perpendicular to both inputs. Use it to find a surface normal from two edges, or to tell whether a target is to your left or right: the sign of the Z component of forward x toTarget says which side.

Python Stand-in: field of view and left or right

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Unreal is left-handed with Y to the right, so with the formula above a positive Z means the target is to the right. This matches the earlier lesson on axes.

Lerp: blending between values

Lerp (linear interpolation) blends from A to B by an alpha from 0 to 1: A + (B - A) * alpha. It works on numbers, vectors, colors and rotators. Common patterns:

  • A door that opens over time: lerp rotation with alpha rising from 0 to 1 in a Timeline.
  • Smoothing a camera: Current = Lerp(Current, Target, 0.1) each frame (or the built-in FInterp To / VInterp To nodes, which take delta time).

Rotators, quaternions and why gimbal lock exists

A Rotator stores Pitch, Yaw, Roll in degrees. It is easy to read and good for editing and simple spinning. A Quaternion uses four numbers and avoids gimbal lock (when two axes line up and one degree of freedom is lost) and interpolates smoothly with Slerp. The engine converts both ways, and many animation systems use quaternions internally. As a rule: edit with rotators, blend and combine with quaternions (for example Combine Rotators, Rotator from Axis and Angle).

Useful rotator helpers:

  • Find Look at Rotation (start, target): the rotation facing the target.
  • Get Forward Vector / Get Right Vector / Get Up Vector of a rotator or actor.
  • Make Rotator, Break Rotator, Delta Rotator, RInterp To.

Transforms

A Transform (FTransform) bundles Location, Rotation (quaternion) and Scale. Many functions work with transforms because they carry all three at once: spawning an actor uses a transform, and attaching converts between world and local space with Transform Location / Inverse Transform Location.

Python Stand-in: lerp, and local to world in 2D

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does normalizing a vector do?

    A normalized vector is a unit vector: same direction, length 1.
  2. 2. The dot product of two unit vectors is 0. What does that mean?

    A dot product of 0 means 90 degrees between the directions.
  3. 3. How do you get the direction from A to B?

    Subtract the start from the end; normalize when you only need the direction.
  4. 4. Why do engines use quaternions internally?

    Quaternions avoid gimbal lock and support smooth slerp blending.

Summary

  • Vectors hold positions and directions; subtract to get direction, normalize for unit length, multiply by speed and delta time to move.
  • Dot product measures alignment; cross product gives a perpendicular vector and tells left from right.
  • Lerp blends values; rotators are for editing, quaternions for blending.
  • Transforms bundle location, rotation and scale; convert between local and world space deliberately.

Next: Static Meshes and Importing Assets