tags:

views:

20

answers:

1

I am using the Corona Gaming Addition SDK to build an iphone / andorid game. I have a space ship on the screen and I will allow the user to rotate the ship 360 degrees. I would like to then call the applyLinearImpulse method to allow the user to thrust the ship forward in the direction the ship is facing.

The method accepts these arguments witch are applied to the ships X and Y in order to move the ship to the new destination. The trick is to figure out what the new X and Y needs to be based on rotation / direction the ship is pointing.

ship:applyLinearImpulse(newX, newY, player.x, player.y)

Anyone done this or have a suggestion on the math that would figure this out?

thanks -m

A: 

Ok .... about 5 min after I posted this I figured it out. Here is the answer

speedX = 0.5 * (math.sin(ship.rotation*(math.pi/180)))
speedY = -0.5 * (math.cos(ship.rotation*(math.pi/180)))

if(event.phase =="began") then
  ship:applyLinearImpulse(speedX, speedY, player.x, player.y)
end
mswallace