Object movement based on rotation

I am working on a little project where I need to rotate a display group, then based on its rotation move it forward along that same angle or backward. The formula

object.x = object.x + math.cos(angle) \* speed; object.y = object.y + math.sin(angle) \* speed;

has worked for me before, so I deployed it here. I am assuming I am doing something wrong, because when I run the code the object does not move the way I want it to. I am posting the code here, hoping that someone can point out my (hopefully) simple mistake.

local \_w = display.contentWidth; local \_h = display.contentHeight; local player, playerGun; local group = display.newGroup(); local angle = 90; local movementSpeed = 5; local updateRotation = function( r ) angle = angle + r; if (angle \> 360) then angle = angle - 360; elseif (angle \< 0) then angle = angle + 0 end print( angle ); end local buttonTapped = function( event ) local e = event.target.id; if (e == "right") then group:rotate(10); updateRotation(10); elseif (e == "left") then group:rotate(-10); updateRotation(-10); elseif (e == "up") then group.x = group.x + (math.cos(angle) \* movementSpeed); group.y = group.y + (math.sin(angle) \* movementSpeed); elseif (e == "down") then group.x = group.x - (math.cos(angle) \* movementSpeed); group.y = group.y - (math.sin(angle) \* movementSpeed); end end local drawDpad = function( event ) local dPadUp = display.newRect(\_w / 2, (\_h / 2) - 75, 50, 50 ); dPadUp.id = "up"; dPadUp:addEventListener("tap", buttonTapped); local dPadDown = display.newRect(\_w / 2, (\_h / 2) + 75, 50, 50 ); dPadDown.id = "down"; dPadDown:addEventListener("tap", buttonTapped); local dPadLeft = display.newRect((\_w / 2) - 75, \_h / 2, 50, 50 ); dPadLeft.id = "left"; dPadLeft:addEventListener("tap", buttonTapped); local dPadRight = display.newRect((\_w / 2) + 75, \_h / 2, 50, 50 ); dPadRight.id = "right"; dPadRight:addEventListener("tap", buttonTapped); end local drawPlayer = function( event ) player = display.newRect( 0, 0, 20, 20 ); playerGun = display.newRect( 0, 15, 5, 10 ); player:setFillColor( 1, 0, 0, 1 ); playerGun:setFillColor( 0, 1, 0, 1 ); group:insert( player ); group:insert( playerGun ); group.x = display.contentCenterX; group.y = display.contentCenterY; group.anchorX = 0.5; group.anchorY = 0.5; end drawDpad(); drawPlayer();

math.sin and cos take angles in radians, not degrees.    Try math.sin(math.rad(angle)), for example.

http://lua-users.org/wiki/MathLibraryTutorial

math.sin and cos take angles in radians, not degrees.    Try math.sin(math.rad(angle)), for example.

http://lua-users.org/wiki/MathLibraryTutorial