Skip to content

Commit

Permalink
Gyro and ballistics computer fix
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LiddulBOFH committed May 10, 2024
1 parent 8d5cd62 commit 18f0df9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lua/acf/entities/turrets/turrets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
7 changes: 5 additions & 2 deletions lua/entities/acf_turret_computer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 18f0df9

Please sign in to comment.