Firing a rotating cannon

Hello

I am trying to make this cannon gameobject where by it constantly rotates in 360 degrees. Whatever other objects collide with it (cannonballs are falling from top), they become centred to the cannon. The cannon still rotates with the cannonball. Basically, I want to be to able to fire the cannonball in whatever direction the cannon is facing. Problem is that I don’t know how to go about coding it, here’s what I have at the moment;

local inverseRotation = \_cannonRot + math.pi; local speedX,speedY = 100\* math.sin(inverseRotation), 100 \*math.cos(inverseRotation) if (e.phase == "began") then target.bodyType = "dynamic" target:applyLinearImpulse(speedX, speedY, target.x, target.y) \_fired = true; return \_fired; end

Problem with this is that it doesn’t fire in the right direction. I basically have a module whereby Cannon is defined, and have a Game module where the collision detection (as well as setting up the game environment) is happening; if the cannonball collides with the cannon, it calls a function within the same Game module;

function placeAtCannon(index, \_cX, \_cY, \_cannonRot, \_fired) local target = cannonBall[index]; target.bodyType = "static" -- set coordinate to centre of cannon target.x = \_cX; target.y = \_cY - 200; function fireTheCannonBall(e) Runtime:removeEventListener("enterFrame", rotateCannonBall) local inverseRotation = \_cannonRot + math.pi; local speedX,speedY = 100\* math.sin(inverseRotation), 100 \* math.cos(inverseRotation) if (e.phase == "began") then target.bodyType = "dynamic" target:applyLinearImpulse(speedX, speedY, target.x, target.y) \_fired = true; return \_fired; end end if (\_fired == true) then target:removeEventListener("touch", fireTheFruit); end target:addEventListener("touch", fireTheCannonBall); --Runtime:addEventListener("enterFrame", rotateCannonBall) --print (\_cX .. " " .. \_cY) end

Thank you