Hello -
This is related to my earlier thread on passing a value from one object to another. BTW, passing the value itself is easy; the rest of the stuff was trickier.
Since I figured out how to rotate a bullet according to the ship’s rotation and make it move forward in relation to its rotation (facing forward), I though I’d apply the same logic to the ship to make it thrust forward in the direction it is facing.
It’s moving in the direction it’s pointing, alright, but it’s doing it awfully slow. Even adding a large number (4000) to shipLinearVelocity near the end of the attached code snippet does not alter the slow velocity. Any clues as to why it’s doing it so slow? Is there another approach?
Thanks, regards.
local function thrustFwd() if touchedThrust == true then -- Play thrust sound -- audio.play( fireSound ) local posX = math.sin( math.rad( ship.rotation )) local posY = math.cos( math.rad( ship.rotation )) ship.x = ship.x + posX ship.y = ship.y - posY local function getLinearVelocity(rotation, velocity) local angle = math.rad(rotation) return { xVelocity = math.sin(angle)\* velocity, yVelocity = math.cos(angle) \* -velocity } end physics.addBody( ship, "dynamic" ) local shipLinearVelocity = getLinearVelocity(ship.rotation, 4000) ship:setLinearVelocity(ship.xVelocity, ship.yVelocity) end end