Fixed function Unit:PredictHealth(time)

Added the future prediction point, we need to add the function input to the current time to get it.
main
mrmoo 1 year ago
parent a22aa67d2a
commit 8eb4a620e5
  1. 8
      src/Unit/Unit.lua

@ -784,7 +784,8 @@ function Unit:PredictHealth(time)
table.remove(self.regression_history, 1)
end
table.insert(self.regression_history, { time = GetTime(), percent = self:GetHP() })
local currentTime = GetTime()
table.insert(self.regression_history, { time = currentTime, percent = self:GetHP() })
for i = 1, #self.regression_history do
local entry = self.regression_history[i]
@ -793,9 +794,12 @@ function Unit:PredictHealth(time)
end
local slope, intercept = self:LinearRegression(x, y)
return slope * time + intercept
return slope * (currentTime + time) + intercept
end
-- Use linear regression to guess the time until a given health percent
---@param percent number
---@return number

Loading…
Cancel
Save