From c7b7737c87b4065cec0c9a754cbadcd45157509b Mon Sep 17 00:00:00 2001 From: thecraftianman <64441307+thecraftianman@users.noreply.github.com> Date: Fri, 25 Oct 2024 19:50:18 -0400 Subject: [PATCH] Wait a tick before retrying bullet flight Addresses #410 --- lua/acf/ballistics/ballistics_sv.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lua/acf/ballistics/ballistics_sv.lua b/lua/acf/ballistics/ballistics_sv.lua index d1f0663a..9f608374 100644 --- a/lua/acf/ballistics/ballistics_sv.lua +++ b/lua/acf/ballistics/ballistics_sv.lua @@ -57,7 +57,9 @@ 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 @@ -65,14 +67,15 @@ function Ballistics.CalcBulletFlight(Bullet) 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) @@ -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