Table of Contents

In Unreal Engine, yaw, pitch, and roll are three fundamental controls used for rotating an object in 3D space.

These three axes of rotation are orthogonal to each other and are typically represented by the letters Y, P, and R respectively.

In this article, we will take a closer look at these controls and how they can be used to manipulate objects in Unreal Engine.

Yaw Control

The yaw control is used to rotate an object around its horizontal axis, which is typically the x-axis in 3D space. Yaw is often used to turn an object horizontally, such as a vehicle or aircraft.

The yaw value can be specified using a value between -π and π radians, where negative values correspond to counterclockwise rotation and positive values correspond to clockwise rotation.

In Unreal Engine, the yaw control is typically implemented using the following code:

csharp

float NewYaw GetComponent<Transform>().rotation.euler.y;

NewYaw + DeltaTime * Input.GetAxis(“Horizontal”); // Add the horizontal input to the yaw value

transform.rotation Quaternion.Euler(NewYaw, 0, 0); // Set the new rotation

Pitch Control

The pitch control is used to rotate an object around its vertical axis, which is typically the z-axis in 3D space. Pitch is often used to turn an object vertically, such as a camera or aircraft.

The pitch value can be specified using a value between -π and π radians, where negative values correspond to downward rotation and positive values correspond to upward rotation.

In Unreal Engine, the pitch control is typically implemented using the following code:

csharp

float NewPitch GetComponent<Transform>().rotation.euler.z;

NewPitch + DeltaTime * Input.GetAxis(“Vertical”); // Add the vertical input to the pitch value

transform.rotation Quaternion.Euler(0, NewPitch, 0); // Set the new rotation

Roll Control

The roll control is used to rotate an object around its longitudinal axis, which is typically the x-axis in 3D space. Roll is often used to turn an object vertically, such as a camera or aircraft.

The roll value can be specified using a value between -π and π radians, where negative values correspond to leftward rotation and positive values correspond to rightward rotation.

In Unreal Engine, the roll control is typically implemented using the following code:

csharp

float NewRoll GetComponent<Transform>().rotation.euler.x;

NewRoll + DeltaTime * Input.GetAxis(“Horizontal”); // Add the horizontal input to the roll value

transform.rotation Quaternion.Euler(NewRoll, 0, 0); // Set the new rotation

Combining Yaw, Pitch, and Roll Controls

In many cases, it is necessary to combine yaw, pitch, and roll controls in order to achieve the desired movement of an object. For example, when flying a plane, the pilot must control both pitch and roll in addition to yaw in order to maintain a stable flight path.

To combine yaw, pitch, and roll controls in Unreal Engine, you can use the following code:

csharp

float NewYaw GetComponent<Transform>().rotation.euler.y;

float NewPitch GetComponent<Transform>().rotation.euler.z;

float NewRoll GetComponent<Transform>().rotation.euler.x;

// Combine the three values to create a new quaternion
csharp

Quaternion NewRotation Quaternion.FromEuler(NewYaw, NewPitch, NewRoll);

transform.rotation NewRotation; // Set the new rotation

Summary

In this article, we have taken a closer look at yaw, pitch, and roll controls in Unreal Engine and how they can be used to manipulate objects in 3D space.