Warcraft III resources & community, 2003–2006 · archived

Unit Slide with slowing

not rated
Submitted by paskovichCalculations0 downloads
A simple script, that can be used to calculate the distance that a unit should be moved with in a timer, to perform a slowing movement, where the speed is 0 in the end.

maxDist is the distance that the unit moves through the whole movement.
n is how many times the timer will expire in total.
count is how many times the timer has expired since start.

Look at my exaple SlideUnit function to understand!

Source

function GetPolarOffset takes real maxDist, real n, integer count returns real
    return 2*maxDist*(count-n-1)/(n-n*n)
endfunction

Comments

2
I think using those PolarProjectionX and Y functions is really ugly :P

Also, writing bj_DEGTORAD out by hand is kinda...

Anyways, assuming that that works, gj :P
function PolarProjectionX takes real x, real distance, real angle returns real
    return x+distance*Cos(angle * (3.14159/180.0))
endfunction
function PolarProjectionY takes real y, real distance, real angle returns real
    return y+distance*Sin(angle * (3.14159/180.0))
endfunction

function GetPolarOffset takes real maxDist, real n, integer count returns real
    return 2*maxDist*(count-n-1)/(n-n*n)
endfunction

function SlideUnit_Child takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t, "unit")
    local real ang = GetHandleReal(t, "angle")
    local integer c = GetHandleInt(t, "counter")
    local real offset = GetPolarOffset(GetHandleReal(t, "maxD"), GetHandleReal(t, "time")/0.01, c)
    call SetUnitX(u, PolarProjectionX(GetUnitX(u), offset, ang))
    call SetUnitY(u, PolarProjectionY(GetUnitY(u), offset, ang))
    if c+1 > GetHandleReal(t, "time")/0.01 then
        call FlushHandleLocals(t)
        call DestroyTimer(t)
    else
        call SetHandleInt(t, "counter", c+1)
    endif
    set t = null
    set u = null
endfunction

function SlideUnit takes unit whichUnit, real distance, real angle, real time returns nothing
    local timer t = CreateTimer()
    call SetHandleHandle(t, "unit", whichUnit)
    call SetHandleReal(t, "angle", angle)
    call SetHandleReal(t, "maxD", distance)
    call SetHandleReal(t, "time", time)
    call TimerStart(t, 0.01, true, function SlideUnit_Child)
    set t = null
endfunction


What do you think?