HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Swirl Spell

07-19-2006, 06:36 AM#1
emjlr3
trying to make a swirling spell(the follwoing is just the basics, to try and get the swirl to actually work first), basically like a periodic movement around a center point, where the center point moves along an angle periodically as well:

Collapse JASS:
function Trig_Swirl_Test_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A006' 
endfunction

function ST_Effects takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local string s = GetAttTable(t)   
    local real x = GetTableReal(s,"x")
    local real y = GetTableReal(s,"y")    
    local real circ = GetTableReal(s,"circ")     
    local real ang = GetTableReal(s,"ang")    
    local integer runs = GetTableInt(s,"runs")  
    local integer dist = GetTableInt(s,"dist")      
    local real xnew = x + 100 * Cos(circ * bj_DEGTORAD)
    local real ynew = y + 100 * Sin(circ * bj_DEGTORAD)  
    
    if runs>25 then
        call Clearst(s,t)
        set t = null                       
    else    
        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl",xnew,ynew))
        call KillTrees( xnew, ynew, 125)
        call SetTableInt(s,"runs",runs+1)
        call SetTableReal(s,"circ",circ+20)
        call SetTableInt(s,"dist",dist+5)
        call SetTableReal(s,"x",x + (dist+5) * Cos(ang * bj_DEGTORAD))
        call SetTableReal(s,"y",y + (dist+5) * Sin(ang * bj_DEGTORAD))        
    endif    
endfunction

function Trig_Swirl_Test_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local location l = GetSpellTargetLoc()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local real xtarg = GetLocationX(l)
    local real ytarg = GetLocationY(l)
    local real ang = ABPXY(x,y,xtarg,ytarg)
    local real xstart = x + 150 * Cos(ang * bj_DEGTORAD)
    local real ystart = y + 150 * Sin(ang * bj_DEGTORAD)                    
    local timer t = CreateTimer()
    local string s = GetAttTable(t)  
    
    call SetTableReal(s,"x",xstart)
    call SetTableReal(s,"y",ystart)    
    call SetTableReal(s,"circ",ang)
    call SetTableReal(s,"ang",ang)    
    call SetTableInt(s,"runs",0)   
    call SetTableInt(s,"dist",150) 
    call TimerStart(t,.1,true,function ST_Effects)    
    
    set u = null
    call RemoveLocation(l)
    set l = null     
endfunction

//===========================================================================
function InitTrig_Swirl_Test takes nothing returns nothing
    set gg_trg_Swirl_Test = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Swirl_Test, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Swirl_Test, Condition( function Trig_Swirl_Test_Conditions ) )
    call TriggerAddAction( gg_trg_Swirl_Test, function Trig_Swirl_Test_Actions )
endfunction

seems to weave just a bit, like a very fine cos/sin curve, hardly noticeable though

any ideas why this could be failing?
07-19-2006, 06:50 AM#2
PipeDream
Neither your intent nor your failure mode is clear to me. If you wish to simply move things about in a circle, then you have two choices:
- Parameterize by angle
Each time step, increase angle by a small amount. Store angle. Place effect at <x,y> = <xcen,ycen> + radius*<cos(angle),sin(angle)>
- Parameterize by x,y
Each time step, <x,y> = <x,y> + angular velocity*(-y,x)/(optional normalization SquareRoot(x^2+y^2))
Store x,y
07-19-2006, 01:57 PM#3
emjlr3
i am pretty sure I am doing method 1

Collapse JASS:
local real xstart = x + 150 * Cos(ang * bj_DEGTORAD)
local real ystart = y + 150 * Sin(ang * bj_DEGTORAD)

is my starting spot, 150 from the caster at the correct angle, this is the spot that will be moved along the cast angle, and around which the effects hould be created, giving the illusion of a swirl

Collapse JASS:
call SetTableReal(s,"x",xstart)
    call SetTableReal(s,"y",ystart)    
    call SetTableReal(s,"circ",ang)
    call SetTableReal(s,"ang",ang)    
    call SetTableInt(s,"runs",0)   
    call SetTableInt(s,"dist",150)

store my locals, my center point as x and y, the real circ, which will be the angle the effects will be created around the center point, ang, which is the cast angle, runs, so I can check the ammount of runs so I can stop it eventually, and dist, which is the starting distance away my center point is, so i can increase this slowly to move my center point

in ST_Effects i get my stored locals, then create the location for my effect

Collapse JASS:
local real xnew = x + 100 * Cos(circ * bj_DEGTORAD)
    local real ynew = y + 100 * Sin(circ * bj_DEGTORAD) 

from the center point, offset 100(each time) at the angle circ, which is increased each run, which should move my effects around the center point in a circle, thus if the center point is also moved, the it should look like a swirl, instead of just a circle

at the end of each run, i update my values

Collapse JASS:
call SetTableInt(s,"runs",runs+1)
        call SetTableReal(s,"circ",circ+20)
        call SetTableInt(s,"dist",dist+5)
        call SetTableReal(s,"x",x + (dist+5) * Cos(ang * bj_DEGTORAD))
        call SetTableReal(s,"y",y + (dist+5) * Sin(ang * bj_DEGTORAD))

runs=runs+1, cuz I check how many runs, and this lets me stop my timer
circ=circ+20, so my angle that the effect is created around the center point keeps going around in a circle
dist=dist+5, so that my center point moves 5 farther each run
and my center point position, x and y


**edit error found, I was storing my values x and y as a polar projection of itself, instead of continueing a polar projection from the caster