# I want to get the angle between the mouse cursor coordinates and the player.

**URL:** <https://forums.unrealengine.com/t/i-want-to-get-the-angle-between-the-mouse-cursor-coordinates-and-the-player/1837634>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, Blueprint, question\
**Created:** [May 3, 2024, 6:47am UTC](https://forums.unrealengine.com/t/i-want-to-get-the-angle-between-the-mouse-cursor-coordinates-and-the-player/1837634 "2024-05-03T06:47:14Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![PoLyFo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/polyfo/32/751636_2.png) [@PoLyFo](https://forums.unrealengine.com/u/PoLyFo)\
**Post date:** [May 3, 2024, 6:47am UTC](https://forums.unrealengine.com/t/i-want-to-get-the-angle-between-the-mouse-cursor-coordinates-and-the-player/1837634/1 "2024-05-03T06:47:14Z")

</div>

Hello !  
I want to find the angle between the two vectors

I’ll show you the picture

 ![qwe.PNG](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/3/4/f34a88efccdd7b3ec78dcc82ffb6ceec7573d506.jpeg)

 ![qwe2.PNG](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/f/5/0f59b133843b3b5021f3637bd65e6632aa1d534b.jpeg)  
It looks like this in the actual game, and I want to get that angle.

This project is Top-Down view

I’ve tried several ways, but I don’t get the result I want, so I’m leaving a question like this.

I would appreciate your help !

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [May 3, 2024, 7:05am UTC](https://forums.unrealengine.com/t/i-want-to-get-the-angle-between-the-mouse-cursor-coordinates-and-the-player/1837634/2 "2024-05-03T07:05:28Z")

</div>

> [@How to get an angle between 2 Vectors?](https://forums.unrealengine.com/t/how-to-get-an-angle-between-2-vectors/280850/2):
>
> 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:** ![DPS](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dps/32/928246_2.png) [@DPS](https://forums.unrealengine.com/u/DPS)\
**Post date:** [May 3, 2024, 7:16am UTC](https://forums.unrealengine.com/t/i-want-to-get-the-angle-between-the-mouse-cursor-coordinates-and-the-player/1837634/3 "2024-05-03T07:16:10Z")

</div>

edit: or just use ClockworkOceans better answer.

Lets call the gun direction **a** and the direction from the gun to the mouse **b**. On top of that lets call the gun location **A** and the world space location of the mouse **B**. I assume you already have **a** and **A**. You can get **B** with “get hit result under mouse” and **b** can be calculated with **B** - **A** , you also need to normalize this value.

Now with **a** and **b** you can calculate the dot product, that is a value between -1 and 1. Add 1 to the value of the dot product and multiply by 0.5. Now subtract this value from 1. This value is 0 if **a** and **b** are the same direction and 1 if they are the opposite direction. Multiply the value by 180.

If you need to know does the angle rotate up or down you need to do this next step. You have another direction **c** , that is perpendicular to the gun direction (gun forward vector). **c** is the up vector of the gun. You get the dot product for **b** and **c** , if this value is less than 0 you multiply the value of the previous step by -1, if it’s 0 or greater then you multiply by 1.

---

<div class="post-metadata">

**Author:** ![PoLyFo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/polyfo/32/751636_2.png) [@PoLyFo](https://forums.unrealengine.com/u/PoLyFo)\
**Post date:** [May 3, 2024, 7:36am UTC](https://forums.unrealengine.com/t/i-want-to-get-the-angle-between-the-mouse-cursor-coordinates-and-the-player/1837634/4 "2024-05-03T07:36:57Z")

</div>

Thanks for the information!  
But I already looked it up before I posted the question,  
I didn’t get the result I wanted when I did it like that…

---

<div class="post-metadata">

**Author:** ![PoLyFo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/polyfo/32/751636_2.png) [@PoLyFo](https://forums.unrealengine.com/u/PoLyFo)\
**Post date:** [May 3, 2024, 7:37am UTC](https://forums.unrealengine.com/t/i-want-to-get-the-angle-between-the-mouse-cursor-coordinates-and-the-player/1837634/5 "2024-05-03T07:37:59Z")

</div>

I tried as you told me, but the expected result didn’t come out.  
I’ll try another way !  
Thank you for helping me !

---

<div class="post-metadata">

**Author:** ![baobao4435](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/baobao4435/32/950790_2.png) [@baobao4435](https://forums.unrealengine.com/u/baobao4435)\
**Post date:** [May 3, 2024, 9:18am UTC](https://forums.unrealengine.com/t/i-want-to-get-the-angle-between-the-mouse-cursor-coordinates-and-the-player/1837634/6 "2024-05-03T09:18:09Z")

</div>

dot product→acosd = angle.  
but top down view?are you going to make an aim offset?

---

<div class="post-metadata">

**Author:** ![PoLyFo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/polyfo/32/751636_2.png) [@PoLyFo](https://forums.unrealengine.com/u/PoLyFo)\
**Post date:** [May 3, 2024, 10:34am UTC](https://forums.unrealengine.com/t/i-want-to-get-the-angle-between-the-mouse-cursor-coordinates-and-the-player/1837634/7 "2024-05-03T10:34:11Z")

</div>

Exactly !  
I need an angle between the position that the mouse cursor points to  
and the character position as a variable of aim offset.

The function that already finds the angle has been implemented with help.

 ![d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/e/7/5e723f5ffd005fc47d9e5c79854cd46d010a97dd.png)

However, I think there is a problem finding the two vector parameters.

 ![bb](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/b/b/4bbab5639e2aabd0b18bfe31ed07d2b4e33e2681.png)

Is there any additional consideration for Top Down View?

---

<div class="post-metadata">

**Author:** ![baobao4435](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/baobao4435/32/950790_2.png) [@baobao4435](https://forums.unrealengine.com/u/baobao4435)\
**Post date:** [May 3, 2024, 11:01am UTC](https://forums.unrealengine.com/t/i-want-to-get-the-angle-between-the-mouse-cursor-coordinates-and-the-player/1837634/8 "2024-05-03T11:01:47Z")

</div>

Those two parameters are directions:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/2/3/123369deeef109f7c429a643936bea6cccc493d4.jpeg)

But top down aim offset doesn’t need so complicated method.  
you could probably have a look at the previous post.[How do I get the character to aim up or down TDS? - #9 by baobao4435](https://forums.unrealengine.com/t/how-do-i-get-the-character-to-aim-up-or-down-tds/1772498/9)

---

<div class="post-metadata">

**Author:** ![PoLyFo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/polyfo/32/751636_2.png) [@PoLyFo](https://forums.unrealengine.com/u/PoLyFo)\
**Post date:** [May 3, 2024, 11:03am UTC](https://forums.unrealengine.com/t/i-want-to-get-the-angle-between-the-mouse-cursor-coordinates-and-the-player/1837634/9 "2024-05-03T11:03:25Z")

</div>

It’s a little ignorant, but I solved it anyway.

 ![캡처](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/2/d/e2da4bc756279320a38f73f26047406870877808.png)

 ![w2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/2/1/e216a6cd5bb548331d2cee5bf762187400083748.png)

When I made BP in this way, I got the desired result value to some extent.

Here, we implemented it to be processed naturally by applying Sample Smoothing to the conditional statement and Aim Offset according to the situation.

---

<div class="post-metadata">

**Author:** ![DPS](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dps/32/928246_2.png) [@DPS](https://forums.unrealengine.com/u/DPS)\
**Post date:** [May 3, 2024, 11:03am UTC](https://forums.unrealengine.com/t/i-want-to-get-the-angle-between-the-mouse-cursor-coordinates-and-the-player/1837634/10 "2024-05-03T11:03:43Z")

</div>

edit: you figured it out on your own

Assuming your function works as expected you can use the following vectors as the inputs: one that points to the mouse position from the player and one that points to the position that is at the same location as the mouse position, but with the z being swapped for the character position z.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [June 2, 2024, 11:04am UTC](https://forums.unrealengine.com/t/i-want-to-get-the-angle-between-the-mouse-cursor-coordinates-and-the-player/1837634/11 "2024-06-02T11:04:03Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
