Understanding the dot product and its use cases can be crucial to creating high-quality experiences in Unreal Engine. The dot product is a mathematical operation that takes two vectors and returns a scalar value. The importance of it is not what it is, but rather what you can do with it. It will assist you in many areas that would have been otherwise difficult to figure out.

## Example Use Cases

To encourage you to learn about it, we are immediately going to dive into examples of what it can do.

**Character Movement**: The dot product can be used to determine the direction a character is facing and how to control its movement based on the angle of the joystick input.**Light Attenuation**: The dot product can be used to calculate the intensity of light at a specific point on an object, taking into account the angle between the light source and the surface normal.**Object Picking**: The dot product can be used to determine the intersection between a ray and an object, allowing for object picking and selection.**AI Vision**: The dot product can be used to simulate an AI character’s line of sight, determining what objects are visible and triggering actions based on visibility.**Particle Effects**: The dot product can be used to determine the orientation of particle emitters, ensuring that particles are emitted in the correct direction and orientation.**Reflections**: The dot product can be used to calculate the angle of incidence between a surface and a ray, allowing for accurate reflections on surfaces.**Collision Detection**: The dot product can be used to determine the angle between two objects, helping to detect and resolve collisions between objects in the game world.**Aim Offset**: The dot product can be used to determine the angle between the gun barrel and the target, allowing for accurate aim offset when firing weapons.**Material Editor**: The dot product can be used in shaders within the Material Editor to create various effects, such as rim lighting, parallax occlusion, and rim reflections.**Ray Tracing**: The dot product can be used in ray tracing algorithms to determine the angle between a ray and a surface, allowing for accurate reflections and refractions in real-time.**Sound Attenuation**: The dot product can be used to calculate the angle between the sound source and the listener, allowing for realistic sound attenuation based on the angle of incidence.**NPC AI**: The dot product can be used to calculate the angle between an NPC and the player character, allowing the NPC to make decisions based on its orientation relative to the player.**Procedural Animation**: The dot product can be used to control the orientation of objects during procedural animation, ensuring that objects are correctly animated and moved in response to player inputs.

These are just a few of the many use cases for the dot product in Unreal Engine. By understanding how to utilize this mathematical operation, game developers can enhance their game and create a more immersive and dynamic player experience.

## How To Interpret The Dot Product

Now that you’ve seen a glimpse of what it can do, we’ll now explain how to interpret its results so that you can use it in your own implementation.

The result of the dot product between two vectors can be interpreted as a scalar value that represents the cosine of the angle between the two vectors. Here’s a breakdown of how to interpret the result:

**Positive Value**: If the dot product of two vectors results in a positive value, it means the angle between the two vectors is less than 90 degrees, or**the vectors are pointing in roughly the same direction.****Zero Value**: If the dot product of two vectors is zero, it means the vectors are orthogonal or**perpendicular**to each other, with**an angle of 90 degrees**between them.**Negative Value**: If the dot product of two vectors is negative, it means the angle between the two vectors is greater than 90 degrees, or the**vectors are pointing in roughly opposite directions.**

### Normalizing Vectors Before Finding Dot Product

Normalizing the vectors ensures that they have a length of 1, and therefore the dot product will only represent the cosine of the angle between the vectors, giving you an accurate representation of the angle regardless of the lengths of the vectors.

If you don’t normalize the vectors, the dot product will still give you a scalar value, but it will not accurately represent the angle between the two vectors.

#### Will the sign be accurate either way?

Yes, the sign of the dot product will still be accurate in determining whether the two vectors are facing toward or away from each other, even if they are not normalized. You can always rely on the negative or positiveness of the result.

#### Does the dot product represent an angle in degrees?

The dot product does not directly represent an angle in degrees. It represents the cosine of the angle between two vectors. To get the actual angle in degrees, you can use the acos function and then convert the result to degrees.

The `acos`

function returns the angle in radians. If you want the angle in degrees, you need to convert the result of `acos`

to degrees.

You can use the FMath::RadiansToDegrees(AngleInRadians) function to convert to degrees.

## Use cases for procedural animation

Lets continue with more example use cases that will encourage you to use the dot product in unreal engine.

How the dot product can be used in Unreal Engine for procedural animation:

**Foot Placement**: The dot product can be used to calculate the angle between the character’s foot and the ground, allowing for accurate foot placement and step size during locomotion animations.**Limb Rotation**: The dot product can be used to determine the orientation of a character’s limbs, allowing for accurate rotation during animations.**IK Solver**: The dot product can be used in an inverse kinematics (IK) solver to calculate the angle between joints, allowing for realistic and flexible animations of characters and objects.**Ragdoll Physics:**The dot product can be used to calculate the angle between joints during ragdoll physics simulations, allowing for accurate and realistic ragdoll animations.**Cloth Simulation**: The dot product can be used to calculate the angle between cloth vertices, allowing for realistic and dynamic cloth simulations.**Blending Animations**: The dot product can be used to calculate the angle between the character’s forward direction and the camera direction, allowing for seamless blending between different animations based on the camera angle.**Bone Constraints**: The dot product can be used to calculate the angle between bones, allowing for constraints and limits to be set for bones during animations.