• News

• Industries

• Learning & Support

• Community

• Marketplace

# How to get angle from three locations?

Hi, anybody has any idea about how can I get an angle from three locations?

If I am thinking what you are trying to do correctly, have one location look at another location. Save the rotation. Look at the other location. Save that rotation as a different var. find the absolute value of the difference. If greater than 180 degrees, subtract 180 degrees.

Hi Thuranius,
Thanks for the answer, I also tried the first part. I did the two variables. But after subtracting I messed up. Can you please help me how to subtract if it is greater than or not 180 degree.
And can I get the result from -180 to 180 range?

It would be easier to break the rotation apart and compare the rotations on one plane (most likely yaw)

Just break the rotation of each rotation variable and subtract the yaw values. Then find the absolute value so that you have a positive number. See if it is greater than 180, then do 360 - your angle. (I was wrong on the math for subtracting 180)

But that should give you the angle.

Hi,
Its just working fine. Thanks. But if I want the value from the rang -180 to 180 like the unreal world shows it, what should I do?
I mean now it shows the value from 0-180 for both sides, I just need that one side will have the value from 0 to 180 and another will have 0 to -180, so then I can differentiate.

Here is a simple way to do it :

^^ That way is simpler than mine. As well as it will be more accurate by looking at the plane the three points are on, versus my way is based off of the world yaw plane.

Here is what I was thinking originally.

Hi Mhousse1247,
Thanks for you ans. I tried it, but may be I did something wrong. Will try this again.
Hi Thuranius,
As I was doing as you did here so Its just working fine. Thanks. But if I want the value from the rang -180 to 180 like the unreal world shows it, what should I do?
I mean now it shows the value from 0-180 for both sides, I just need that one side will have the value from 0 to 180 and another will have 0 to -180, so then I can differentiate.

Hi Thuranius,
As in your image where one ball is in front of the character and another is left side of him. So its showing 107 degree. But if there is another ball on the right side as a mirror of the left side ball, the value will still show 107 degree. I just want to make the left -107 and the right 107 degree. Can you suggest something?

Hi Mhousse1247,
Yours way also worked. Its simple but both these ways give output to only positive angle value. Can you please suggest something which will return the value from -180 to 180 like the unreal world?

Are working on 2D or 3D game?

it is a 3d project, RTS. So the characters have different rotations.

If it’s a top down view , multiply the angle by this :

May be I missed something. Let me explain my situation. The black axis is world axis. Character can be faced to any direction according to the world. The red one is the character axis. The black round mark is the destination where the character is moving. And the yellow mark is the mouse cursor which is moving continuously and I need to know that angle according to the character in positive and negative for the right and the left side of the character. Right now from this solution I am getting the angel from 0 to 180 for the right and left both side. I just need to get the opposite value for left and right side of the character axis. May be now you can realize the situation.

This is why I asked 2d or 3d, and here is a 2D situation
In your case ( based on character orientation) here is how to do things :

You can still use mine, just remove everything from the abs and beyond. Angle 1 would be your destination and Angle 2 would be your mouse cursor.

Here is what I got from it. Math went weird over 180 degrees, hence the added math. But it works perfectly. White sphere is destination, green circle is the cursor.

Hi Thuranius,
Now it shows positive and negative value, but now it also gives values less than -180. Like -280 or others. Can you please fix it?

Hi Mhousse1247,
Thank you. I tried as the way you did. It shows the positive and negative value for the right and left side. But something is not right. Because It does not show the full 0 to 180 range. Sometimes it shows the range only 0 to 130 /140 or some other fractions and also the angel varies on distance. Is there something with the transition by ACOS or Radian to degree? Can you please check if it is working perfectly in your case?

That’s because your points are not on the same plane :