Jump to content
  • Advertisement
Sign in to follow this  
xyuri

Maths problem with moving object at angle.. (Cos/Sin)

This topic is 5042 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 am making an asteroids game and cant get my ship to move correctly ... I have revised on some algebra and mostly understand it but not completely how to apply it. My little ship gains momentum but does not slow down for now (this is intentional) This is how it gains momentum:
object.XVel += cos(object.angle) * (ACCELERATION * TimeFrame);
object.YVel += sin(object.angle) * (ACCELERATION * TimeFrame);
And this is how I move the ship aroumd:
object.XPos += cos(object.angle) * (object.Velocity * TimeFrame);
object.YPos += sin(object.angle) * (object.Velocity * TimeFrame);
The only problem is when I change the angle of the ship it changes the direction it is traveling in to what seems like a random direction .... This is how it turned out: http://www.xyuri.com/OpenGL Test.exe Can anyone help me out with this one? EDIT: also, if I do (sin(30) * 1) on my calculator I get (0.5) but using the functions in c++ I get (-0.988032) Why is this? [Edited by - xyuri on December 4, 2004 5:24:32 PM]

Share this post


Link to post
Share on other sites
Advertisement
First of all, C math functions take their arguments in radians, so try that and see if it fixes the problem.

Also, if you go to the trouble of updating XVel and YVel, why not just add them directly to XPos and YPos? And where does object.Velocity come from? Maybe I'm seeing things out of context and there's no problem there, but I thought I'd mention it.

Share this post


Link to post
Share on other sites
Remember to convert to and from radians. Programming languages typically use radians in their math functions, but people generally think in degrees. 360 degrees = 2*pi radians, so to convert to radians multiply by pi/180; divide by that to convert back.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!