Warcraft III resources & community, 2003–2006 · archived

UnitCircleLoc

not rated
Submitted by AltSubmitterFunctions0 downloads
This function lets you have a unit move in a circle around a point. It requires the Handle Var API that is also available here at the vault. I haven't tested speeds higher than 100 -- I'm not sure they will be stable. You could use this for all sorts of nifty effects, circling fire for instance.

Also, this stores a boolean on the unit called "stopCircling." Setting this to true will cause the unit to stop. You can also change the unit boolean "clockwise" while the unit is rotating and it will switch directions.

Source

function UnitCircleLoc_Child takes nothing returns nothing
    local timer this = GetExpiredTimer()
    local unit whichUnit = H2U(GetHandleHandle(this, "whichUnit"))
    local location where = Handle2Loc(GetHandleHandle(this, "where"))
    local real radius = GetHandleReal(this, "radius")
    local real currentAngle = GetHandleReal(this, "currentAngle")
    local boolean clockwise = GetHandleBoolean(whichUnit, "clockwise")
    local location tempLoc = null
    local boolean stopCircling = GetHandleBoolean(whichUnit, "stopCircling")

    if(stopCircling) then
        call PauseTimer(this)
        call FlushHandleVars(this)
        call DestroyTimer(this)
        return
    endif

    if(clockwise) then
        set currentAngle = currentAngle - 1
    else
        set currentAngle = currentAngle + 1
    endif

    set tempLoc = PolarProjectionBJ(where, radius, currentAngle)

    call SetUnitPositionLoc(whichUnit, tempLoc)

    call RemoveLocation(tempLoc)

    call SetHandleReal(this, "currentAngle", currentAngle)
endfunction

//Make a stop function that changes a gamecache value
//Store clockwise boolean on unit so direction can be reversed
function UnitCircleLoc takes unit whichUnit, location where, real radius, real speed, boolean clockwise returns nothing
    local timer t = CreateTimer()

    call SetHandleHandle(t, "whichUnit", whichUnit)
    call SetHandleHandle(t, "where", where)
    call SetHandleReal(t, "radius", radius)
    call SetHandleReal(t, "currentAngle", GetRandomReal(0,360))
    call SetHandleBoolean(whichUnit, "clockwise", clockwise)
    call SetHandleBoolean(whichUnit, "stopCircling", false)

    call TimerStart(t, 1/speed, true, function UnitCircleLoc_Child)
endfunction

Comments

0

No comments.