Get angle of line based on worldspace

So i’m trying to get an angle of a line render that will return the same regardless of what point you start at. So for example, my current code looks like this

angle = Mathf.Atan2(Object1.y - Object2.y, Object1.x - Object2.x) * 180 / Mathf.PI;

Which works great but the issue is, if I have two objects. I want to return the same angle regardless of what object is 1 and and 2.

For example. I have two objects to draw a line between. I draw a straight line from right to left and I return an angle of 0. If i draw the line right to left I get 180.

It doesn’t matter what number it returns, because it won’t show to the player. I just need it to be consistent.

Thanks!

1 Answer

1

Figured it out lol

 angle = Mathf.Atan((Object1.y - Object2.y) / (Object1.x - Object2.x));

Good luck on anyone that finds this