There are a few things you can improve on your code.
The first is a way to calculate the angle. Instead
ship.rotation*(math.pi/180)
You can do it:
local inverseRotation = ship.rotation + math.pi
Addition is faster than division and multiplication. In addition, storing it on a variable allows you not to calculate it twice. Then you can do:
local inverseRotation = ship.rotation + math.pi
local speedX, speedY = 0.5 * math.sin(inverseRotation), -0.5 * math.cos(inverseRotation)
Hello!
source
share