Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Problem in finding Angle?

This topic is 5154 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I m studyig about the Character animation in a tutorial. Character rotation is contolled by the mouse move. He is using a float value as angle the character is facing but i can''t understand how he calculated it. Can anybody plz explain it Movex = (TargetPos.x - CuurentPos.x ) / Distance * Speed Movey = (TargetPos.y - CuurentPos.y ) / Distance * Speed MoveZ = (TargetPos.z - CuurentPos.z ) / Distance * Speed YAngle = atan2(MoveX, Movez);----->How XAngle = -atan(MoveY);----->How Thanks

Share this post


Link to post
Share on other sites
Advertisement
it's basic trig.

to find the angle around the Y axis, it's like projecting your entities on the (X, Z) plane. then using trig, the angle required to rotate the ship towards the target,

tan(angle) = moveX / moveZ

=> angle = atan(moveX / moveZ);

atan2 is better, as it gives you quadrant as well.

for the angle around the X axis (the pitch angle),

tan(xangle) = movey / sqrt(movex*movex + movez*movez)

assuming (movex*movex + movez*movez) = 1

xangle = atan(movey)

the sign depends which way you want the ship to pitch up.

draw that stuff on paper. it's easier. first, draw it from the top (the piece of paper is the (X, Z) plane).

[edited by - oliii on April 11, 2004 5:34:03 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!