• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Calculating Arcs

Status
Not open for further replies.
Level 4
Joined
Feb 3, 2007
Messages
58
Im currently developing a realistic arc system, basically it moves a unit from point a to point b in an arc. I need to use timers to do the loop thought but I have no idea how to use timers. So I need lots o help, heres the script:
JASS:
function PolarProjectionX takes real x, real dist, real angle returns real
    return x+dist*Cos(angle*bj_DEGTORAD)
endfunction
function PolarProjectionY takes real y, real dist, real angle returns real
    return y+dist*Sin(angle*bj_DEGTORAD)
endfunction
function ArcUnit takes unit u, real xA, real yA, real xB, real yB, real maxheight returns nothing
    local real steps
    local real halfpoint
    local real PointAx 
    local real PointAy             
    local real dist 
    local real height = GetUnitFlyHeight(u)
    local real angle = GetUnitFacing(u)
    set PointAx = xA
    set PointAy = yB
    set dist = SquareRoot( (xB-PointAx)*(xB-PointAx)+(yB-PointAy)*(yB-PointAy))
    set steps = dist/30
    set halfpoint = dist/2
    call SetUnitFacing(u, bj_RADTODEG * Atan2(yB - yA, xB - xA))
    loop
        exitwhen GetUnitX(u) == xB
        exitwhen GetUnitY(u) == yB
        set PointAx = PolarProjectionX( PointAx, steps, GetUnitFacing(u))
        set PointAy = PolarProjectionY( PointAy, steps, GetUnitFacing(u))
        if steps < halfpoint then
            set height = height+20
            call SetUnitFlyHeight(u,height,0)
            set steps = steps-1 
            call SetUnitX(u, PointAx)
            call SetUnitY(u, PointAy)
        else                                
            set height = height-20 
            call SetUnitFlyHeight(u,height,0)
            call SetUnitX(u, PointAx)
            call SetUnitY(u, PointAy)
            set steps = steps-1
        endif
    endloop
    endfunction
 
Level 4
Joined
Feb 3, 2007
Messages
58
That could use a lot of optimizing, and it's a triangle, not an arc, currently.

As for the formula for an arc, if you want that, check this out.

As for timers, check this out.

Thanks for those links, what do I use the Arc Calculation for? Do I just use it to set the max height or something?
I know it will resuly in a triangular arc, I made the mistake of deaccelerating the rate at which the unit move and should of decreased the height, Ill fix that.
 
Level 4
Joined
Feb 3, 2007
Messages
58
So assuming im correct, I need to store the original distance between point a and point b (maxdist), and in the timer loop it recalculates with the current distance between the unit and point b (dist), and maxdist.
 
Status
Not open for further replies.
Top