From 18f0df9fe97bc3fdcc11771bf914a650f94ce32d Mon Sep 17 00:00:00 2001 From: LiddulBOFH <13317534+LiddulBOFH@users.noreply.github.com> Date: Fri, 10 May 2024 11:54:22 -0500 Subject: [PATCH] Gyro and ballistics computer fix Tentative fix for gyro stabilization, testing showed much more promising results Also fixed ballistic computer's prediction to properly use that last result's flight time when predicting the next intercept position I forgot to push these changes way earlier --- lua/acf/entities/turrets/turrets.lua | 6 ++++-- lua/entities/acf_turret_computer/init.lua | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lua/acf/entities/turrets/turrets.lua b/lua/acf/entities/turrets/turrets.lua index 5a43d062a..655fff00c 100644 --- a/lua/acf/entities/turrets/turrets.lua +++ b/lua/acf/entities/turrets/turrets.lua @@ -182,12 +182,14 @@ do -- Turret drives if Turret.Manual then return Rotator:WorldToLocalAngles(Turret:LocalToWorldAngles(Angle(0, math.Clamp(-Turret.DesiredDeg,Turret.MinDeg,Turret.MaxDeg), 0))).yaw else - local LocalDesiredAngle = ClampAngle(Turret:WorldToLocalAngles(Turret.DesiredAngle) - Angle(0,StabAmt,0),Angle(0,-Turret.MaxDeg,0),Angle(0,-Turret.MinDeg,0)) + local AngDiff = Turret.Rotator:WorldToLocalAngles(Turret.LastRotatorAngle) + local LocalDesiredAngle = ClampAngle(Turret:WorldToLocalAngles(Turret.DesiredAngle) - Angle(0,StabAmt,0) - AngDiff,Angle(0,-Turret.MaxDeg,0),Angle(0,-Turret.MinDeg,0)) return Rotator:WorldToLocalAngles(Turret:LocalToWorldAngles(LocalDesiredAngle)).yaw end else - return Turret.Manual and (Rotator:WorldToLocalAngles(Turret:LocalToWorldAngles(Angle(0, -Turret.DesiredDeg, 0))).yaw) or (Rotator:WorldToLocalAngles(Turret.DesiredAngle).yaw - StabAmt) + local AngDiff = Turret.Rotator:WorldToLocalAngles(Turret.LastRotatorAngle) + return Turret.Manual and (Rotator:WorldToLocalAngles(Turret:LocalToWorldAngles(Angle(0, -Turret.DesiredDeg, 0))).yaw) or (Rotator:WorldToLocalAngles(Turret.DesiredAngle + AngDiff).yaw - StabAmt) end end, diff --git a/lua/entities/acf_turret_computer/init.lua b/lua/entities/acf_turret_computer/init.lua index 104cb73f9..5e18c3eba 100644 --- a/lua/entities/acf_turret_computer/init.lua +++ b/lua/entities/acf_turret_computer/init.lua @@ -462,7 +462,6 @@ do -- Metamethods and other important stuff local FlightDistance = Sim.Pos:Distance(Sim.NextPos) - Sim.FlightTime = Sim.FlightTime + DeltaTime Sim.TotalTime = Sim.TotalTime + DeltaTime debugoverlay.Line(Sim.StartPos + Sim.Pos,Sim.StartPos + Sim.NextPos,5,Color(255,0,0),true) @@ -476,6 +475,7 @@ do -- Metamethods and other important stuff if (Dir:Dot(Point - Sim.Pos) >= 0) and (Dir:Dot(Point - Sim.NextPos) <= 0) then local Ratio = (Sim.Pos:Distance(Point)) / FlightDistance + Sim.FlightTime = Sim.FlightTime + (DeltaTime * Ratio) debugoverlay.Line(Sim.StartPos + Sim.Pos,Sim.StartPos + Sim.NextPos,8,Color(0,255,0),true) debugoverlay.Cross(Sim.StartPos + Sim.Pos,15,8,Color(255,0,0),true) @@ -489,6 +489,7 @@ do -- Metamethods and other important stuff return self:AdjustSimulation() else + Sim.FlightTime = Sim.FlightTime + DeltaTime Sim.FlightDistance = Sim.FlightDistance + FlightDistance end else @@ -501,10 +502,12 @@ do -- Metamethods and other important stuff Sim.Pos = Sim.Pos + ((Sim.NextPos - Sim.Pos) * Ratio) - Sim.FlightDistance = Sim.FlightDistance + (FlightDistance * Ratio) + Sim.FlightTime = Sim.FlightTime + (DeltaTime * Ratio) + Sim.FlightDistance = Sim.FlightDistance + (FlightDistance * Ratio) return self:AdjustSimulation() else + Sim.FlightTime = Sim.FlightTime + DeltaTime Sim.FlightDistance = Sim.FlightDistance + FlightDistance end end