• ### What is your GameDev Story?

#### Archived

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

# Problem in finding Angle?

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

## 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 on other sites
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]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 17
• 14
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634097
• Total Posts
3015505
×