Skip to content

Commit

Permalink
Wait a tick before retrying bullet flight
Browse files Browse the repository at this point in the history
Addresses #410
  • Loading branch information
thecraftianman committed Oct 25, 2024
1 parent 67bd78c commit c7b7737
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lua/acf/ballistics/ballistics_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,25 @@ function Ballistics.RemoveBullet(Bullet)
end

function Ballistics.CalcBulletFlight(Bullet)
if Bullet.KillTime and Clock.CurTime > Bullet.KillTime then
local ClockTime = Clock.CurTime

if Bullet.KillTime and ClockTime > Bullet.KillTime then
return Ballistics.RemoveBullet(Bullet)
end

if Bullet.PreCalcFlight then
Bullet:PreCalcFlight()
end

local DeltaTime = Clock.CurTime - Bullet.LastThink
local Drag = Bullet.Flight:GetNormalized() * (Bullet.DragCoef * Bullet.Flight:LengthSqr()) / ACF.DragDiv
local DeltaTime = ClockTime - Bullet.LastThink
local Flight = Bullet.Flight
local Drag = Flight:GetNormalized() * (Bullet.DragCoef * Flight:LengthSqr()) / ACF.DragDiv
local Accel = Bullet.Accel or ACF.Gravity
local Correction = 0.5 * (Accel - Drag) * DeltaTime

Bullet.NextPos = Bullet.Pos + ACF.Scale * DeltaTime * (Bullet.Flight + Correction)
Bullet.Flight = Bullet.Flight + (Accel - Drag) * DeltaTime
Bullet.LastThink = Clock.CurTime
Bullet.NextPos = Bullet.Pos + ACF.Scale * DeltaTime * (Flight + Correction)
Bullet.Flight = Flight + (Accel - Drag) * DeltaTime
Bullet.LastThink = ClockTime
Bullet.DeltaTime = DeltaTime

Ballistics.DoBulletsFlight(Bullet)
Expand Down Expand Up @@ -278,7 +281,9 @@ function Ballistics.DoBulletsFlight(Bullet)

if Ballistics.TestFilter(Entity, Bullet) == false then
table.insert(Bullet.Filter, Entity)
Ballistics.DoBulletsFlight(Bullet) -- Retries the same trace after adding the entity to the filter, important incase something is embedded in something that shouldn't be hit
timer.Simple(0, function()
Ballistics.DoBulletsFlight(Bullet) -- Retries the same trace after adding the entity to the filter; important in case something is embedded in something that shouldn't be hit
end)

return
end
Expand Down

0 comments on commit c7b7737

Please sign in to comment.