I need to find the angle between a directional look vector and a static position. I know I can do this with dot products but that method isn’t suitable for me because of the fact that inverse cosine only returns positive values. I need to be able to return both negative and positive angles. I’ve attached some images below to better illustrate what I’m trying to do.
In 2d is easy, but in 3d is kind of complicated. For 2d
local d1, d2 = TargetDirection, Facing
local angle = math.acos(d1:Dot(d2)) * (math.acos(d1.Y*d2.X-d1.X*d2.Y) > math.pi/2 and 1 or -1)
the left part of the * is for the angle, while the other is for checking which side the direction is (left or right).
You may also notice that i did not use dot product for the other one, and that is because i rotated d1 by 90 degrees, which is used to check which side its facing