Shots fire beside ship

Hello i am making an spaceship game and having my ship shoot all the time without pushing a button all good so long:

local function playerShoot() bullet = display.newRect( sceneGroup, ship\_menu.x - 5, ship\_menu.y - 50, 2, 20 ) bullet:setFillColor( 1,1,1 ) transition.to( bullet, {y = \_T - bullet.height, delay = 5, time = 500, onComplete = playerShoot} ) end

But when i move my ship sideways the shots fired don’t keep up. The shots gets fired besides the ships cannon, is where a better way to do this?

local shipController = function ( event ) if (event.phase == "moved") then ship\_menu.x = event.x end end Runtime:addEventListener( "touch", shipController )

Kind regards

/Isak

Dont use transition.to() to shoot bullets… use something like appleForce() or applyLinearLelocity()

Good Luck!

Okey, But why does make a difference? is that more instant?

Well display.newRect() will create your bullet centered on ship_menu.x - 5 and ship_menu.y - 50 and it’s going to move to where it’s .y is equal to _T whatever value that is. We can’t see because we don’t have enough code. Is ship_menu your ship or do you have another object that is the ship?

Rob

Hey Rob,

The ship_menu is the object, and it is working now with applyForce:) i guess the problem was that transitioned the bullet instead of applying force:)

Dont use transition.to() to shoot bullets… use something like appleForce() or applyLinearLelocity()

Good Luck!

Okey, But why does make a difference? is that more instant?

Well display.newRect() will create your bullet centered on ship_menu.x - 5 and ship_menu.y - 50 and it’s going to move to where it’s .y is equal to _T whatever value that is. We can’t see because we don’t have enough code. Is ship_menu your ship or do you have another object that is the ship?

Rob

Hey Rob,

The ship_menu is the object, and it is working now with applyForce:) i guess the problem was that transitioned the bullet instead of applying force:)