|
Hello Everybody... I'm currently working on a project which requires me to do something I just can't figure out. I need to know the angle between two objects facing directions. Let me explain; if you look down on two arrows, with the heads down the x-axis, rotated randomly, around the y-axis. Now I need to know the angle between the two arrowheads. So if the two arrows face away from each other I need an angle of 180 degrees, and If they face the same direction I need an angle of 0 degrees. I tried everything from trigonometric functions to simple unity references, and nothing seems to work how I want it, I have a hunch the Vector3.Angle could work, but so far it doesn't.
(comments are locked)
|
|
Vector3.Angle gives you the angle between two directions. Just put transform.forward of both objects in there, and it should give you the angle you need. It has one limitation, though, it doesn't distinguish between CW and CCW. I wrote a function for that: It returns 1.0 for CW, -1.0 for CCW and 0.0, if the angle between the two objects is 0. here it is in C#
Mar 08 at 08:55 PM
BobBobson108
Sorry for not marking you answers a correct sooner. As the question posted was an analogy for just a part of what I was doing I tried a lot of methods out, including yours and coming to the conclusion I was thinking about it in a wrong fashion. I ended up using a combination of vector calculations and trigonometry to achieve the effect I was looking for. Nevertheless for the question I posted this was a fulfilling answer. And it did help me.
Mar 09 at 02:44 AM
MaeniAck
(comments are locked)
|
