I want to be able to keep track of the ‘bullets’ position, and check if it has hit any of the objects on screen. However I fear having a number of these objects could create issues where it might no always detect the hit in time.
local function Shoot()
if ShootDebounce then return end
ShootDebounce = true
local NewBullet = Bullet:Clone()
NewBullet.Position = UDim2.new(0, Ship.Position.X.Offset, 0, Ship.AbsolutePosition.Y)
NewBullet.Parent = Bullets
coroutine.wrap(function()
local ObjectHit = false
while true do
if ObjectHit then break end -- Object has been hit
if NewBullet.AbsolutePosition.Y <= -NewBullet.AbsoluteSize.Y then break end -- Off screen
NewBullet.Position = UDim2.new(0, NewBullet.Position.X.Offset, 0, NewBullet.Position.Y.Offset - BULLET_SPEED)
-- Check if bullet has hit an object
for _, v in pairs(Objectives:GetChildren()) do
end
wait()
end
NewBullet:Destroy()
end)()
wait(BULLET_WAIT)
ShootDebounce = false
end