Feadur 122 Report post Posted March 20, 2007 Sorry for such a newbie question, but, given a StartPosition (Vector3) and a EndPosition (Vector3), I have a MoveVector (Vector3). How do I find the angle that my object is facing?. i.e.: Start (10,0,10) End (1,0,5) Then... Move (9,0,5) Which angle is Move creating?? 0 Share this post Link to post Share on other sites
Koobazaur 1264 Report post Posted March 20, 2007 An angle relative to what? If you mean the X,Y,Z axises (?) then you just use trig. If you mean a plane, find the angle between your vector and the plane normal; to do that, calculate the dot product (using quaternions) and solve for itA*B = ||A||*||B||cos(angle between A and B) 0 Share this post Link to post Share on other sites
Feadur 122 Report post Posted March 20, 2007 Actually it's easier than that. The object is moving always along the (0,1,0) plane,so i need to rotate the object so that it's facing to a point in the same plane. 0 Share this post Link to post Share on other sites
iMalc 2466 Report post Posted March 20, 2007 Quote:Original post by FeadurActually it's easier than that. The object is moving always along the (0,1,0) plane,so i need to rotate the object so that it's facing to a point in the same plane.(0,1,0) is not a plane. Describing a plane mathematically generally requires four values. Three values would indicate you're describing a vector. Do you mean that the object is only varying by the y coordinate?That still doesn't answer which plane you want to find the angle with, so I'm afriad I can't help you (yet). 0 Share this post Link to post Share on other sites
Koobazaur 1264 Report post Posted March 20, 2007 I think he mean the plane normal, meaning, it would be the XZ plane.If that is the case, you can use something like atan(Z/X) to find the counter-clockwise angle from the x axis (looking from the top). Be careful of when the X is equal to zero and when you are outside the (-90:90) degree range! 0 Share this post Link to post Share on other sites
Feadur 122 Report post Posted March 20, 2007 Thanks a lot Koobazaur, I have this working now :)public void LookAt(Vector3 point){ Vector3 move = point - this.position; this.rotation.Y = (float)Math.Atan(move.X / move.Z); if (move.Z < 0) this.rotation.Y += (float)Math.PI;} 0 Share this post Link to post Share on other sites
jyk 2095 Report post Posted March 20, 2007 Quote:Original post by FeadurThanks a lot Koobazaur, I have this working now :)public void LookAt(Vector3 point){ Vector3 move = point - this.position; this.rotation.Y = (float)Math.Atan(move.X / move.Z); if (move.Z < 0) this.rotation.Y += (float)Math.PI;}I suggest you make the following changes to the above code excerpt:public void LookAt(Vector3 point){ Vector3 move = point - this.position; this.rotation.Y = (float)Math.Atan2(move.X, move.Z); if (move.Z < 0) this.rotation.Y += (float)Math.PI;}This will solve the 'divide by zero' problem mentioned earlier, and also eliminate the need to compute the quadrant manually.This is of course assuming you have an 'atan2' function available. 0 Share this post Link to post Share on other sites
Feadur 122 Report post Posted March 20, 2007 Thanks jyk, i'm using that function now ;) 0 Share this post Link to post Share on other sites