Hello. I'm using Unity3d to create a simple turret simulation and I have run in to a problem.
I need to find the angle to an object from the turret in 3d space.
Up to this point I thought I could just take the (arc)trig values retrieved from certain perspectives (ie. looking towards the turret from X+ or Y+). Unity uses the left-hand coordinate system, with Y+ being upward and Z+ forward.
However in many tests the turret does not aim directly at the object. I have determined that the problem is the length of my direction vector. After being normalized it is indeed 1 unit in length but this is in 3d space which means that length is longer than comparable 2d vectors (having the same position from an orthographic perspective along an axis). This fact is making all of my inverse trig functions give me incorrect values for this problem.
So my question is:
Can somebody provide me with a mathematical solution and explanation of it (for my own learning)? I can work out the code sure enough I just do not know the mathematics to solve it.