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

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

## 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 on other sites
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 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 on other sites
Yay, it works!

Thank you very much fella's :-)

##### Share on other sites
You're welcome :-)

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633759
• Total Posts
3013720
×