# How to get an angle between 2 Vectors?

**URL:** <https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850>\
**Category:** Blueprint\
**Tags:** unreal-engine, vector, Blueprint, question\
**Created:** [April 17, 2014, 8:24am UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850 "2014-04-17T08:24:59Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Demonicated](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Demonicated](https://forums.unrealengine.com/u/Demonicated)\
**Post date:** [April 17, 2014, 8:24am UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/1 "2014-04-17T08:24:59Z")

</div>

Is there a built in function to find the angle between 2 points (2D and 3D) for HUD and World?

I love SOH CAH TOA, but l love clean code/blueprints more

---

<div class="post-metadata">

**Author:** ![PeterLNewton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PeterLNewton](https://forums.unrealengine.com/u/PeterLNewton)\
**Post date:** [April 17, 2014, 10:16am UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/2 "2014-04-17T10:16:35Z")

</div>

Whats Up **Demonicated** ,

Have you tried the Node **Find Look At Rotation**? This returns angle of rotation between two points. By plugging in just the X & Y into a vector for 2D, you obtain similar results but one less axis.

_Peace_

---

<div class="post-metadata">

**Author:** ![FullMetalDom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FullMetalDom](https://forums.unrealengine.com/u/FullMetalDom)\
**Post date:** [May 18, 2014, 1:17pm UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/3 "2014-05-18T13:17:24Z")

</div>

The best way is to actually make the function you need. It’ll work for any vector (2d or 3d).

You need to INPUT TWO DIRECTION VECTORS in WORLD SPACE.

First. Make a new function.  
Make it have 2 inputs - VectorA and VectorB - and one output - a float.

Take the two vector values and normalize them.

Then take the two results and find the Dot product.

Then use the ACos Node to find the inverse Cos of the Dot product.

Voila.

 ![6508-anglebetweenvectors.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/7/2/372a5dc71072ab9a812f1fdaa19849d2c913126a.jpeg)

---

<div class="post-metadata">

**Author:** ![Zeustiak](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zeustiak](https://forums.unrealengine.com/u/Zeustiak)\
**Post date:** [May 18, 2014, 10:59pm UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/4 "2014-05-18T22:59:37Z")

</div>

Nice. So the float essentially = degrees or do you need another step to finish the conversion?

---

<div class="post-metadata">

**Author:** ![FullMetalDom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FullMetalDom](https://forums.unrealengine.com/u/FullMetalDom)\
**Post date:** [May 19, 2014, 2:23am UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/5 "2014-05-19T02:23:42Z")

</div>

The ACos function has two possible outputs - degrees and Radians. Up to you which you prefer.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_adaa14ef1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_adaa14ef1](https://forums.unrealengine.com/u/anonymous_user_adaa14ef1)\
**Post date:** [June 22, 2014, 2:30pm UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/6 "2014-06-22T14:30:16Z")

</div>

Exactly what it should be.  
Here is the equivalent code.  
`float AimAtAngle = ((acosf(FVector::DotProduct(PlayerDirection, MouseDirection))) * (180 / 3.1415926));`

---

<div class="post-metadata">

**Author:** ![Ryan\_Darcey](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ryan\_Darcey](https://forums.unrealengine.com/u/Ryan_Darcey)\
**Post date:** [November 9, 2014, 10:14pm UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/7 "2014-11-09T22:14:38Z")

</div>

EdwardCoughlan, note that you could replace:

```
float AimAtAngle = ((acosf(FVector::DotProduct(PlayerDirection, MouseDirection))) * (180 / 3.1415926));

```

with this to make it a little cleaner:

```
float AimAtAngle = FMath::RadiansToDegrees(acosf(FVector::DotProduct(PlayerDirection, MouseDirection)));
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_27ca9f66](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_27ca9f66](https://forums.unrealengine.com/u/anonymous_user_27ca9f66)\
**Post date:** [June 3, 2016, 3:33pm UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/8 "2016-06-03T15:33:38Z")

</div>

Hey guys !

Just a quick question…I recreated the above graph in the image and the angle is ok but it’s always positive. I need this for an ai to determine if it should go left or right. Could you please show me how I could get the sign of the angle as well ? I know there is a way using cross product but I haven’t figured it out yet. Thanks !

---

<div class="post-metadata">

**Author:** ![KhalimWu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KhalimWu](https://forums.unrealengine.com/u/KhalimWu)\
**Post date:** [June 3, 2016, 4:46pm UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/9 "2016-06-03T16:46:56Z")

</div>

just insert a simple bool, if Xend-Xini \<0, the angle is going to the left, else its to the right. adjust to your needs. also, this is a 2 years old one, you should open a new one.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_27ca9f66](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_27ca9f66](https://forums.unrealengine.com/u/anonymous_user_27ca9f66)\
**Post date:** [June 4, 2016, 5:41am UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/10 "2016-06-04T05:41:43Z")

</div>

Hey jblaswu ! Thanks for the quick response. Sorry about the post thing, I thought it would be more appropriate to post it here. Anyway…who is Xend and Xini ? this is for an AI controller…not the player. The AI doesn’t know where left and right is…I am giving it an angle and it just moves in that direction. The problem is that the angle is always positive.

---

<div class="post-metadata">

**Author:** ![FullMetalDom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FullMetalDom](https://forums.unrealengine.com/u/FullMetalDom)\
**Post date:** [June 4, 2016, 5:50am UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/11 "2016-06-04T05:50:08Z")

</div>

Hey Cosmos,  
It depends on exactly what sort of AI you’re making and what sort of functionality you’re trying to achieve.  
I’d use the find look at rotation for the most part.  
More info?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_27ca9f66](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_27ca9f66](https://forums.unrealengine.com/u/anonymous_user_27ca9f66)\
**Post date:** [June 4, 2016, 7:02am UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/12 "2016-06-04T07:02:13Z")

</div>

It’s a dual character system similar to last of us. Player controls one character and the AI controls the other character. What I need is to give the AI an angle so that I can trigger the animation for it to turn towards the player. (I am using root motion for both characters). I just realised that even if I get the right angle it won’t do the job because AI needs the navigation path otherwise it would turn into a wall.

---

<div class="post-metadata">

**Author:** ![FullMetalDom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FullMetalDom](https://forums.unrealengine.com/u/FullMetalDom)\
**Post date:** [June 4, 2016, 9:07am UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/13 "2016-06-04T09:07:02Z")

</div>

Oh, dude.  
Just use the inbuilt navigation system if you can. Go check out those tutorials. It creates the path then follows it around obstacles on the navmesh, you just give it a target position.

---

<div class="post-metadata">

**Author:** ![Vaheva](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vaheva/32/963466_2.png) [@Vaheva](https://forums.unrealengine.com/u/Vaheva)\
**Post date:** [November 23, 2017, 8:12pm UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/14 "2017-11-23T20:12:50Z")

</div>

Simple and best - thx!

---

<div class="post-metadata">

**Author:** ![spaceharry](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@spaceharry](https://forums.unrealengine.com/u/spaceharry)\
**Post date:** [December 18, 2017, 10:28am UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/15 "2017-12-18T10:28:39Z")

</div>

This is from the VR Expansion Plugin for the “shortest” angle between two vectors.

```
FVector vec1;
FVector vec2;

float Angle = 0.0f;
FVector nAxis;

FQuat BetweenQuat = FQuat::FindBetweenVectors(vec1, vec2);

BetweenQuat.ToAxisAndAngle(nAxis, Angle);

```

Angle will then be in radians.

---

<div class="post-metadata">

**Author:** ![thebenjiman](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/thebenjiman/32/577800_2.png) [@thebenjiman](https://forums.unrealengine.com/u/thebenjiman)\
**Post date:** [January 24, 2018, 10:41am UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/16 "2018-01-24T10:41:00Z")

</div>

For those like me who rely on this angle in order to get a result between -180 and 180; for exemple to make an animation go Clockwise or CounterClockwise, you need to subtract the atan of the second vector to the first like so:

 ![228220-anglebetweentwovectors.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/6/9/c69f08686831fbfca8024c8c0977e59c151b885a.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8c09e5641](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8c09e5641](https://forums.unrealengine.com/u/anonymous_user_8c09e5641)\
**Post date:** [July 19, 2018, 11:10am UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/17 "2018-07-19T11:10:29Z")

</div>

Note that Unreal Math already has a function to “unwind” any angle to -180-180: `FMath::UnwindDegrees`. I’m not sure if it’s directly supported in Blueprints, but you could wrap it if not.

---

<div class="post-metadata">

**Author:** ![Interference369](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Interference369](https://forums.unrealengine.com/u/Interference369)\
**Post date:** [October 22, 2018, 7:41pm UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/18 "2018-10-22T19:41:23Z")

</div>

In Blueprints - “Clamp Axis” function

---

<div class="post-metadata">

**Author:** ![SimplestWay](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SimplestWay](https://forums.unrealengine.com/u/SimplestWay)\
**Post date:** [October 23, 2018, 6:24am UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/19 "2018-10-23T06:24:30Z")

</div>

Clamp Axis returns an angle between 0 to 360 degrees.

---

<div class="post-metadata">

**Author:** ![Interference369](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Interference369](https://forums.unrealengine.com/u/Interference369)\
**Post date:** [October 23, 2018, 7:29am UTC](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/20 "2018-10-23T07:29:10Z")

</div>

Yes, but also changes the -180/180 degree to positive values. I should write more clearly

[Next page](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850.md?page=2)
