function SlideUnit_Execute()
local t = GetExpiredTimer()
local u = SLIDE_DATA[t].u
local v = SLIDE_DATA[t].v
local a = SLIDE_DATA[t].a
SetUnitX(u, GetUnitX(u) + v * Cos(a))
SetUnitY(u, GetUnitY(u) + v * Sin(a))
if SLIDE_DATA[t].i >= SLIDE_DATA[t].q then
SLIDE_DATA[t] = nil
PauseTimer(t)
DestroyTimer(t)
else
SLIDE_DATA[t].i = SLIDE_DATA[t].i + 1
end
t,u,v,a = nil,nil,nil,nil
end
SLIDE_DATA = {}
function SlideUnit(u,distance,angle,duration)
local t = CreateTimer()
SLIDE_DATA[t] = {
u = u
,v = distance / duration * 0.01
,a = angle * bj_DEGTORAD
,q = R2I(duration / 0.01)
,i = 0
}
TimerStart(t, 0.01, true, SlideUnit_Execute)
t = nil
end
--every time u call slide unit a timer is created which keeps moving unit under angle passed as param, every 0.01 seconds by "(param_distance / param_duration) * 0.01"
--so if you want to move some unit by 500.00 dist over 2 seconds in the current unit facing direction, it will basically move that unit every 0.01 seconds by 2.5 in the direction which that unit faced at the moment you called the slide function
--its set that every 0.1 seconds slide unit function is called which moves unit by 50*factor in current unit facing direction over 1 second
--if unit is turning what happens is that old timers keep moving it in the old direction and new in the new direction, which looks like the unit has been slowed down a little bit
function slide_it()
local u = CreateUnit(Player(0), FourCC('hfoo'), GetPlayerStartLocationX(Player(0)),GetPlayerStartLocationY(Player(0)), 270)
local trig = CreateTrigger()
local factor = 1.0 -- this is what makes unit move faster by time
TriggerRegisterTimerEventPeriodic(trig, 0.1)
TriggerAddAction(trig, function()
SlideUnit(u,50*factor,GetUnitFacing(u),1)
factor = factor >= 1.6 and factor or factor + 0.005 -- factor incrasing means unit moves faster max factor value is set to 1.6, but you can ofc change logic here a little bit
end)
end