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!
Answer by obviousturtlegames · Aug 04, 2020 at 12:25 AM
Figured it out lol
angle = Mathf.Atan((Object1.y - Object2.y) / (Object1.x - Object2.x));
Good luck on anyone that finds this
Your answer
Follow this Question
Related Questions
Move an object in a circular path according to touch position 1 Answer
Moving a GameObject in an Ellipsoid path 1 Answer
Move a game object away from another game object based on the angle difference 1 Answer
Help Detecting side of an vector 3, How to check direction and face between 2 vector3 0 Answers
Why is my knockback direction script inconsistent with it's knockback direction? 1 Answer