I got it.
The way to make the bullet continue in a straight line is to find the difference between the starting x and y and the ending x and y. You then add this difference to the x and y to get the next point on the line.
Not sure why that took me so long. Like I said, it’s been a while since my last math class.
Thanks for all your help!
Oh, and here is the code in case you wanted it:
[lua]local background = display.newRect (0, 0, 320, 480)
background.alpha = 0.1
local machineGunX = 0
local machineGunY = 0
local playerObject = display.newCircle (160, 240, 20)
local function machineGun(event)
if event.x > playerObject.x + 60 then
machineGunX = machineGunX + event.x
machineGunX = event.x - playerObject.x
machineGunY = event.y - playerObject.y
local machineGunB = display.newCircle (playerObject.x, playerObject.y, 5)
transition.to(machineGunB, {time=800, x=event.x + machineGunX*6, y=event.y + machineGunY*6})
end
if event.x < playerObject.x - 60 then
machineGunX = machineGunX + event.x
machineGunX = event.x - playerObject.x
machineGunY = event.y - playerObject.y
local machineGunB = display.newCircle (playerObject.x, playerObject.y, 5)
transition.to(machineGunB, {time=800, x=event.x + machineGunX*6, y=event.y + machineGunY*6})
end
if event.y < playerObject.y - 60 then
machineGunX = machineGunX + event.x
machineGunX = event.x - playerObject.x
machineGunY = event.y - playerObject.y
local machineGunB = display.newCircle (playerObject.x, playerObject.y, 5)
transition.to(machineGunB, {time=800, x=event.x + machineGunX*6, y=event.y + machineGunY*6})
end
if event.y > playerObject.y + 60 then
machineGunX = machineGunX + event.x
machineGunX = event.x - playerObject.x
machineGunY = event.y - playerObject.y
local machineGunB = display.newCircle (playerObject.x, playerObject.y, 5)
transition.to(machineGunB, {time=800, x=event.x + machineGunX*6, y=event.y + machineGunY*6})
end
end
background:addEventListener(“tap”, machineGun)[/lua] [import]uid: 102017 topic_id: 18051 reply_id: 69235[/import]