close to the fix, but not really. the math.clamp in the first section of the progress variable is useless and your if statement can be a bit buggy as it can give false truths due to how floats work in computers. (unless roblox has an internal thingy to compensate which im not sure)
I have a question about the module. Does it support speed changes while the movement is happening? I tried setting the speed var to lets say 0 to stop the movement in place but it teleported it to the very beginning. Is there any supported way of changing the speed ?
the calculations is just TimePassed / TotalpathTime.
heres a pseudocode example.
--outside loop
local Speed = 5
local StartTime = tick()
local Enemy = {}
local PathObject = bezierpath.new(args)
--in loop
Enemy.AlphaValue += (tick() - StartTime) / (PathObject:GetPathLength() / Speed)
StartTime = tick()
if you want it to be a bit more optimized you could save the alpha value when an enemies speed changes and only cange the AlphaValue variable and StartTime variable when their speed is changed. but this just makes it a bit easier to handle changing speed IMO.
If youâre wondering why does the mob restart when you set the speed to something else, here is the correct formula.
local currentTime = tick()
local elapsedTime = currentTime - StartTime
T = elapsedTime / TotalTime
if Speed ~= mob.Stats.Walkspeed.Value then
local currentDistance = T * Path:GetPathLength()
Speed = mob.Stats.Walkspeed.Value
TotalTime = Path:GetPathLength() / Speed
T = currentDistance / Path:GetPathLength()
StartTime = currentTime - T * TotalTime
end