Jump to content
• Advertisement

#### Archived

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

# Calculate x angle orientation from x and z position

This topic is 5280 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

I have a jet that will soon travel to another position. everything works fine as long as the x angle is not 0 I use direct3d so x is right, y is up, z forward my calc was vec1 is source vec2 is destination newvec = vec2 - vec1 newvec = normalize(newvec) so y = newvec.y * (PI/2) that works fine and when the x angle is not 0 it works great 2 but when want him to go to a negative z( towards the screen) he doesnt because x is already 0. So it doesnt work so x = newvec.x * ( PI/2) * ( newvec.z/abs(newvec.z) ) I though multiplying x by a -1 or 1 would spin my jet around in the right direction. Please help. Its my last hurdle in this space fight simulation. Or at least that I can see. Nick

#### Share this post

##### Share on other sites
Advertisement
Perhaps you should stick to standard maths rather than inviting your own laws of maths .

if you have vec1 source, vec2 destination...

direction = vec2-vec1
normalise(direction)

you can move your "jet" like so:

position += direction*speed*frametime

where direction was calculated above, speed is the speed that your "jet" should travel at (in units/sec) and frametime is the amount of time passed since the last frame (in seconds).

#### Share this post

##### Share on other sites
Well I''m not reinbventing the wheel. it still moves according to its Look orientation. But when I tell the jet "Hey fly to this x,y,z) coordinate I have to know the exact orientation. so I get the x angle. But the x depends on whether hes going -z or +z, so I need to add 180 to his degree to determine the correct flow.

It doesnt have anything to do with actually moving it, just the orientation

#### Share this post

##### Share on other sites
What SpaceDude probably mean is that you use stranges formulas to get the displacement and not reinventing the wheel since what you use seems incorect (why *(Pi/2) for example ?). He told you the formulas you need though. To get the angle between two vectors you can use arctan but you don''t need it in that case ...

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633409
• Total Posts
3011702
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!