Get angle of two Vector3s
Hello community Here is my situation in 2D Unity: I have a linerenderer. The renderer has two points. I want the linerenderer to have a collider so baseically I make a collider that is big enough and then want to rotate the gameobject it is on by the angle PointA has to PointB.
So for example: PointA = -10, -10, 0 PointB= 10, 10, 0 The angle between them is 45° I wanted to use Vector3.Angle() to get this angle but it always returns a value that is almost 180°. Its never exactly 180° though.
So, does anybody have a solution to this problem and could also explain the reason for this angle-madness to me because I will probably need it again and would like to understand it :D
Thanks in advance
Answer by cjdev · Feb 05, 2016 at 12:40 AM
The reason is because the Angle method measures the two vectors as if they were rays starting at the origin and going through the point given. Because 10,10 and -10,-10 are opposite each other relative to the origin the return from the method is 180 degrees.
Well honestly I'm not really sure where you're getting 45 degrees from. But in the general case you subtract the offsetting vector to find the vector that starts at the origin in order to measure it against something. In your case I suppose you might be thinking of Angle(B-A, (1,0)) which is the vector from A to B measured against the positive x-axis.
@cjdev Well I get the 45° if i have point A and then want its angle to pointB on the x-axis.... so yeah But i think i have a solution now so thanks alot :D