Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using PGELua for the PlaystationPortable. I would just like to know how to make a 2D sprite move in the direction that the sprite is facing.

When the sprite is blitted to the screen it should be heading down the y axis (like it's moving up the screen) but it doesn't appear to be working that way. As far as I am aware, the angles of the images use radians for the rotations.

I have this in a function

function FUNC_MOVE_SHIP(speed,angles)
    VAR_SHIPX = VAR_SHIPX + pge.math.sin(angles) * speed
    VAR_SHIPY = VAR_SHIPY + pge.math.cos(angles) * speed

and I call it in my main program like

    if pge.controls.held(PGE_CTRL_LEFT) then
    elseif pge.controls.held(PGE_CTRL_RIGHT) then
share|improve this question
How DOES it appear to be working? – aaaaaaaaaaaa Jan 9 '12 at 23:11
up vote 2 down vote accepted

A common problem with using radians is that they start to the right. Look at this picture (from Wikipedia):


As you can see, it starts at 0 on the right of the circle and goes counter-clockwise around the circle until it hits 2 * PI. So if your sprite isn't pointing to the right with a rotation of 0, you might have to add some constant. Eg. if your sprite is pointing up, you have to add PI * 0.5 to the calculated angle. Also, instead of adding and subtracting 0.01 from the angle, I'd rather choose some fraction of PI instead. Eg. PI / 90 equals 2 degrees of rotation per update.

share|improve this answer
This is brilliant, thanks! – Richard Sparrow Jan 10 '12 at 11:35

I believe that your movement formula should only work if the angles value is in degrees. To convert radians to degree simply multiply the radian value by 180 and divide it by pi.

share|improve this answer
This is very helpful, I never understood (looking at other code) why there was a lot of 180/pge.math.pi() – Richard Sparrow Jan 10 '12 at 11:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.