What I’m trying to code here is a “shotgun shell” for a cannon, name being a canister shot. How I’ve created it is having a table that indexes all of the actual bullets, then for every frame calculate each shot by iterating over a table. (Key of the table is the bullet, value of the table is the actual velocity) IMO this seems quite resource heavy but I really don’t know what else to do. This is done on the server side.
My problem is, I have a quite large game; the place itself starts with a heartbeat delta time of 60 fps, and whenever I fire a canister shot the heartbeat time (or whatever it is called) drops significantly to about 20fps, and causes the bullet trajectory to slow down. Does anyone else have any advice on how to remedy this? (but on my separate place (which is bare and just the cannons), there is no distinct delta time drop when the canister is fired) If you need more info please let me know, elsewise if this is just a game thing that can’t be changed let me know as well
for i=1,30 do
local InaccuracyFactor = Muzzle.CFrame:VectorToWorldSpace(Vector3.new(math.random(-40,40)/100,math.random(-40,40)/100,math.random(-10,10)/100))
local Velocity = (Muzzle.CFrame.LookVector) * 10 + InaccuracyFactor
local newpart = CanisterRoot:Clone()
newpart.Parent = CanisterModel
newpart.Orientation = Muzzle.Orientation
newpart.Position = Muzzle.Position
CanisterList[newpart] = Velocity
end
coroutine.resume(coroutine.create(function()
local StartTick = tick()
repeat
RunService.Heartbeat:Wait()
for Part,Vel in pairs(CanisterList) do
local ray = Ray.new(Part.Position,Vel)
local hit,position = workspace:FindPartOnRayWithIgnoreList(ray, IgnoreList)
Part.Position = position
CanisterList[Part] = Vel - Vector3.new(0,.1,0)
if hit and hit.Parent:FindFirstChild("Humanoid") then
HandleCanisterDamage(position, hit, Occupant)
CanisterList[Part] = nil
Part:Destroy()
end
if hit and hit.Name ~= "CanisterHitDirt" and hit.CanCollide and not hit.Parent:FindFirstChild("Humanoid") then
HandleCanister(position)
Debris:AddItem(Part, 10)
CanisterList[Part] = nil
end
end
until tick() - StartTick >= 10
for i,v in pairs(CanisterList) do
Debris:AddItem(i, 10)
CanisterList[i] = nil
end
end))