I have a object that is always rotating with a cannon. I want to shoot a bullet, but when I do, it goes always to the right direction instead of the cannon direction. I tried to offset the bullet. What I am doing wrong?
local function go(event)
display.remove(logo)
display.remove(begin)
local planet = display.newImage(“images/earth.png”)
planet.x = centerX
planet.y = centerY
– Esta função faz a terra rodar e aumento a sua rotação por cada 10 segundos
local function animate()
planet.rotation = planet.rotation + 2
earthRotation = timer.performWithDelay( 10000, animate)
end
Runtime:addEventListener(“enterFrame”,animate);
planet:scale(4, 4)
transition.to( planet, { time = 200, xScale = 1, yScale = 1, onComplete = animate} )
startGame()
timerGame()
timeCount()
local function firebullet()
local bullet = display.newCircle( planet.x, planet.y, 2 )
physics.addBody( bullet, { density=3.0, friction=0.5, bounce=0.05 } )
bullet.isBullet = true
function getBulletOffset(planet, offsetAngle, offsetDist )
local offset = math2d.angle2Vector( planet.rotation + offsetAngle, true )
offset = math2d.scale( offset, offsetDist )
return planet.x + offset.x, planet.y + offset.y
end
local bulletStartX, bulletStartY = getBulletOffset( planet, 90, 15 )
bullet.angularVelocity = 50
bullet:applyForce( 100, 0, bullet.x, bullet.y )
local bulletStartX, bulletStartY = getBulletOffset( planet, 90, 15 )
end
bg:addEventListener ( “tap”, firebullet)
end
begin:addEventListener ( “tap”, go)
