View Full Version: Movement At An Angle

C++ Game Dev > Help > Movement At An Angle


Title: Movement At An Angle
Description: Really Simple I know but...


TheDarkJay - July 29, 2006 08:56 AM (GMT)
Sorry for asking so simple a question, but does anyone know how I can make a sprite move at a given angle.

So say I have a ball at position 100 100. I want it to move at a 80 degree angle. How would I do this?

netman - July 29, 2006 12:01 PM (GMT)
Hmm I think this should be some sin and cos calculations.
First you need to say wich degree system you want. the one where 0 degrees is right and when the ammount increases the direction goes anti-clockwise.
Or the one where 0 is up and direction is clockwise.

If you want the first you can do something like this:
CODE
x += cos(angle) * speed;
y += sin(angle) * speed;

Please note that the angle is in radians (the calculation above).
A little thingie to change radians to degrees and back:
CODE
radians = degrees/57.2958

and
CODE
degrees = radians*57.2958




* Hosted for free by InvisionFree