Jump to content
  • Advertisement


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


Shooting / maths q

This topic is 5408 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. Ok, Im trying to let the player fire a projectile. When you click the "fire" key, I do this: xMove = (float)sin(heading*piover180) * MoveDistance; zMove = (float)cos(heading*piover180) * MoveDistance; yMove = (float)sin(lookupdown*piover180) * MoveDistance; The names might look familiar to tutorial readers These figures are then added to the projectile position each frame, which works fine. The problem is that the higher or lower you shoot, the more off the aim is, and its impossible to shoot stright up or down. My maths isnt great I know, but what am I doing wrong? Thanks... zoidy

Share this post

Link to post
Share on other sites
Your "y" goes up and down without affecting the "x" and "z".

Just put a breakpoint right at where xMove is assigned, and look at what values come out for xMove, yMove, and zMove, and you''ll see what it is.

And, for the reader who don''t have your code: you need to scale xMove and zMove by cos(lookupdown*piover180).

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.

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!