Exploring Dot Products in Unity @WorldOfZeroDevelopment
Exploring Dot Products in Unity  @WorldOfZeroDevelopment
Uploaded January 2019 | Updated November 2026, 3 hours ago
Dot Products are a really easy and fun way to compare Vectors in space. When comparing two normalized with a dot product the result will be the cosine of the angle between the two Vectors. This means that for normalized Vectors the results will be:

| Alignment | Result |
| ------------------- | ----------- |
| Parallel | 1 |
| Anti-Parallel | -1 |
| Orthogonal | 0 |

Taking the ArcCosine of these values will return the angle between the two Vectors (Note that Unity uses radians for most calculations so you may need to convert to degrees yourself).

Lets explore some applications of Dot Products and show off how to take advantage of them in your games or other projects. For example, how can you detect if a point is inside of a cone? Perhaps as a way to check if an enemy AI can see the player or another reason. A second example may be detecting the difference in orientation between joysticks and a vehicles orientation to detect if a turn or thrust is the appropriate action to perform when moving.

The formula for dot products is the sum of the product of each axis. For example the dot product of two vectors A and B would be:

* In 2D space: `(A.x * B.x) + (A.y * B.y)`
* In 3D space: `(A.x * B.x) + (A.y * B.y) + (A.z * B.z)`
* In 4D space: `(A.x * B.x) + (A.y * B.y) + (A.z * B.z) + (A.w * B.w)`
* This formula can be expanded as the dimensions continues to increase if you need it to.

Note: Because of this formula the length of the Vectors being compared in the dot product *does* matter!

***

A similar application of dot products but in shader form in our revealing flashlight shader: youtu.be/b4utgRuIekk

An example of using dot products to help control how a top down spaceship uses it's thrusters and rotation: youtu.be/TUIHY-5MvWQ

Source Code for this series is available on GitHub: github.com/WorldOfZero/top-down-spaceship

Join the World of Zero Discord server: discord.gg/hU5Kq2u
Exploring Dot Products in UnityAutomatically Processing Assets with Custom Unity Asset PipelinesTaking a Look at Groovy @Memoized FunctionsBuilding OBS Overlays in Unity 3DAnimating the Elevator - An Elevator Between Scenes - Part 1Improving the Voxel Cube with Lighting and Optimized UpdatesExpanding our Mindustry Server with Custom Maps, Saves and MoreBuilding a Custom Unity Terrain ShaderBuilding a Static Website from Markdown with HugoI Learn About Stencil Buffers and Cutting Holes in ThingsBuilding an Editor Window - Unity Observer - Part 0Building a Cloud Game w/ @MicrosoftReactor - Day 2
World of Zero |

Exploring Dot Products in Unity

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER