HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Spell Trouble

04-05-2006, 04:17 AM#1
emjlr3
basically im trying to create 4 dummy units around the caster that circle the caster, going in and out distance wise( as well as set their facing so it looks like they are going around in a circle), my script seems good from my standpoint, but in game it just looks horribly choppy, almost as if the units arent being put at the correct spot, any ideas? the in and out part seems to work fine, but the circle motion just looks like ass

Collapse JASS:
function Trig_Firefly_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00G' 
endfunction

function Firefly_Effects takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t,"u")
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local unit fire1 = GetHandleUnit(t,"fire1") 
    local unit fire2 = GetHandleUnit(t,"fire2") 
    local unit fire3 = GetHandleUnit(t,"fire3") 
    local unit fire4 = GetHandleUnit(t,"fire4") 
    local real x2
    local real y2  
    local real x3
    local real y3
    local real ang
    local real time = GetHandleReal(t,"time")
    local integer dist = GetHandleInt(t,"dist") 
    local integer change = GetHandleInt(t,"change")      
    
    if GetUnitState(fire1,UNIT_STATE_LIFE)>0 then
        set x2 =  GetUnitX(fire1)
        set y2 = GetUnitY(fire1)
        set ang = AngleBetweenPointsXY(x,y,x2,y2)
        set x3 = x + dist * Cos(ang+1 * bj_DEGTORAD)
        set y3 = y + dist * Sin(ang+1 * bj_DEGTORAD)
        set ang =  AngleBetweenPointsXY(x2,y2,x3,y3)
        call SetUnitFacing(fire1,ang)
        call SetUnitPosition(fire1,x3,y3)  
    endif
    if GetUnitState(fire2,UNIT_STATE_LIFE)>0 then
        set x2 =  GetUnitX(fire2)
        set y2 = GetUnitY(fire2)
        set ang = AngleBetweenPointsXY(x,y,x2,y2)
        set x3 = x + dist * Cos(ang+1 * bj_DEGTORAD)
        set y3 = y + dist * Sin(ang+1 * bj_DEGTORAD)
        set ang =  AngleBetweenPointsXY(x2,y2,x3,y3)
        call SetUnitFacing(fire2,ang)
        call SetUnitPosition(fire2,x3,y3)  
    endif
    if GetUnitState(fire3,UNIT_STATE_LIFE)>0 then
        set x2 =  GetUnitX(fire3)
        set y2 = GetUnitY(fire3)
        set ang = AngleBetweenPointsXY(x,y,x2,y2)
        set x3 = x + dist * Cos(ang+1 * bj_DEGTORAD)
        set y3 = y + dist * Sin(ang+1 * bj_DEGTORAD)
        set ang =  AngleBetweenPointsXY(x2,y2,x3,y3)
        call SetUnitFacing(fire3,ang)
        call SetUnitPosition(fire3,x3,y3)  
    endif
    if GetUnitState(fire4,UNIT_STATE_LIFE)>0 then
        set x2 =  GetUnitX(fire4)
        set y2 = GetUnitY(fire4)
        set ang = AngleBetweenPointsXY(x,y,x2,y2)
        set x3 = x + dist * Cos(ang+1 * bj_DEGTORAD)
        set y3 = y + dist * Sin(ang+1 * bj_DEGTORAD)
        set ang =  AngleBetweenPointsXY(x2,y2,x3,y3)
        call SetUnitFacing(fire4,ang)
        call SetUnitPosition(fire4,x3,y3)  
    endif    
    if dist>400 then
        call SetHandleInt(t,"change",-2)
    elseif dist<75 then
        call SetHandleInt(t,"change",2)
    endif
    if time>30 then
        call KillUnit(fire1)
         
        call ClearTimer(t)
    else
        call SetHandleReal(t,"time",time + .03)
    endif
    call SetHandleInt(t,"dist",dist+change)
    
    
    set u = null    
    set fire1 = null
    set fire2 = null
    set fire3 = null
    set fire4 = null
endfunction

function Trig_Firefly_Actions takes nothing returns nothing
    local timer t = CreateTimer()  
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local unit fire1 = CreateUnit(p,'n005',x + 200 * Cos(0 * bj_DEGTORAD),y + 200 * Sin(0 * bj_DEGTORAD),bj_UNIT_FACING)
    local unit fire2 = CreateUnit(p,'n005',x + 200 * Cos(90 * bj_DEGTORAD),y + 200 * Sin(90 * bj_DEGTORAD),bj_UNIT_FACING)
    local unit fire3 = CreateUnit(p,'n005',x + 200 * Cos(180 * bj_DEGTORAD),y + 200 * Sin(180 * bj_DEGTORAD),bj_UNIT_FACING)
    local unit fire4 = CreateUnit(p,'n005',x + 200 * Cos(270 * bj_DEGTORAD),y + 200 * Sin(270 * bj_DEGTORAD),bj_UNIT_FACING)  
    
    call SetHandleHandle(t,"u",u)
    call SetHandleHandle(t,"fire1",fire1)
    call SetHandleHandle(t,"fire2",fire2)
    call SetHandleHandle(t,"fire3",fire3)
    call SetHandleHandle(t,"fire4",fire4)     
    call SetHandleInt(t,"dist",200)  
    call SetHandleInt(t,"change",2) 
    call SetHandleReal(t,"time",0)  
    call TimerStart(t, .05, true, function Firefly_Effects)
    
    set u = null
    set p = null
    set fire1 = null
    set fire2 = null
    set fire3 = null
    set fire4 = null
endfunction

//===========================================================================
function InitTrig_Firefly takes nothing returns nothing
    set gg_trg_Firefly = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Firefly, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Firefly, Condition( function Trig_Firefly_Conditions ) )
    call TriggerAddAction( gg_trg_Firefly, function Trig_Firefly_Actions )
endfunction
04-05-2006, 04:27 AM#2
Chuckle_Brother
just one thing that MAY make it shorter. Since you store them as fire1 - fire4 just use:

Collapse JASS:
c=1
loop
    exitwhen c == 5
    set unit=GetHandleUnit(t, "fire" + I2S(c))
    set c=c+1
endloop

Oh and don't use angle between points, that will always look goofy if the target unit moves around. Use a fixed real that you increment every time, its just a bit easier IMO
04-05-2006, 04:35 AM#3
emjlr3
that was the best way i could think of of getting the corerct angle facing, else id have to set it at the beggining, and experiment until I get it correct

anyways, any ideas why the movement looks so bad

hmm yea that fixed the circular movement, still trying to figure out the facing problem though

Collapse JASS:
function Trig_Firefly_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00G' 
endfunction

function Firefly_Effects takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t,"u")
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local unit fire1 = GetHandleUnit(t,"fire1") 
    local unit fire2 = GetHandleUnit(t,"fire2") 
    local unit fire3 = GetHandleUnit(t,"fire3") 
    local unit fire4 = GetHandleUnit(t,"fire4")     
    local real ang1 = GetHandleReal(t,"ang1")
    local real ang2 = GetHandleReal(t,"ang2")
    local real ang3 = GetHandleReal(t,"ang3")
    local real ang4 = GetHandleReal(t,"ang4")
    local real fac1 = GetHandleReal(t,"fac1")
    local real fac2 = GetHandleReal(t,"fac2")
    local real fac3 = GetHandleReal(t,"fac3")
    local real fac4 = GetHandleReal(t,"fac4")
    local real time = GetHandleReal(t,"time")
    local integer dist = GetHandleInt(t,"dist") 
    local integer change = GetHandleInt(t,"change")      
    
    if GetUnitState(fire1,UNIT_STATE_LIFE)>0 then        
        call SetUnitFacing(fire1,fac1)
        call SetUnitPosition(fire1,x + dist * Cos(ang1 * bj_DEGTORAD),y + dist * Sin(ang1 * bj_DEGTORAD)) 
        call SetHandleReal(t,"ang1",ang1+4) 
        call SetHandleReal(t,"fac1",fac1+4)
    endif
    if GetUnitState(fire2,UNIT_STATE_LIFE)>0 then        
        call SetUnitFacing(fire2,fac2)
        call SetUnitPosition(fire2,x + dist * Cos(ang2 * bj_DEGTORAD),y + dist * Sin(ang2 * bj_DEGTORAD)) 
        call SetHandleReal(t,"ang2",ang2+4)
        call SetHandleReal(t,"fac2",fac2+4) 
    endif
    if GetUnitState(fire3,UNIT_STATE_LIFE)>0 then        
        call SetUnitFacing(fire3,fac3)
        call SetUnitPosition(fire3,x + dist * Cos(ang3 * bj_DEGTORAD),y + dist * Sin(ang3 * bj_DEGTORAD)) 
        call SetHandleReal(t,"ang3",ang3+4) 
        call SetHandleReal(t,"fac3",fac3+4) 
    endif
    if GetUnitState(fire4,UNIT_STATE_LIFE)>0 then        
        call SetUnitFacing(fire4,fac4)
        call SetUnitPosition(fire4,x + dist * Cos(ang4 * bj_DEGTORAD),y + dist * Sin(ang4 * bj_DEGTORAD)) 
        call SetHandleReal(t,"ang4",ang4+4)
        call SetHandleReal(t,"fac4",fac4+4)  
    endif    
    if dist>400 then
        call SetHandleInt(t,"change",-3)
    elseif dist<250 then
        call SetHandleInt(t,"change",3)
    endif
    if time>30 then
        call KillUnit(fire1)
        call KillUnit(fire2)
        call KillUnit(fire3) 
        call KillUnit(fire4)
        call ClearTimer(t)
    else
        call SetHandleReal(t,"time",time + .03)
    endif
    call SetHandleInt(t,"dist",dist+change)
    
    
    set u = null    
    set fire1 = null
    set fire2 = null
    set fire3 = null
    set fire4 = null
endfunction

function Trig_Firefly_Actions takes nothing returns nothing
    local timer t = CreateTimer()  
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local unit fire1 = CreateUnit(p,'n005',x + 200 * Cos(0 * bj_DEGTORAD),y + 200 * Sin(0 * bj_DEGTORAD),bj_UNIT_FACING)
    local unit fire2 = CreateUnit(p,'n005',x + 200 * Cos(90 * bj_DEGTORAD),y + 200 * Sin(90 * bj_DEGTORAD),bj_UNIT_FACING)
    local unit fire3 = CreateUnit(p,'n005',x + 200 * Cos(180 * bj_DEGTORAD),y + 200 * Sin(180 * bj_DEGTORAD),bj_UNIT_FACING)
    local unit fire4 = CreateUnit(p,'n005',x + 200 * Cos(270 * bj_DEGTORAD),y + 200 * Sin(270 * bj_DEGTORAD),bj_UNIT_FACING)  
    
    call SetHandleHandle(t,"u",u)
    call SetHandleHandle(t,"fire1",fire1)
    call SetHandleHandle(t,"fire2",fire2)
    call SetHandleHandle(t,"fire3",fire3)
    call SetHandleHandle(t,"fire4",fire4) 
    call SetHandleReal(t,"ang1",0) 
    call SetHandleReal(t,"ang2",90) 
    call SetHandleReal(t,"ang3",180) 
    call SetHandleReal(t,"ang4",270)
    call SetHandleReal(t,"fac1",0) 
    call SetHandleReal(t,"fac2",90) 
    call SetHandleReal(t,"fac3",180)
    call SetHandleReal(t,"fac4",270)           
    call SetHandleReal(t,"lvl",GetUnitAbilityLevel(u,'A00G'))
    call SetHandleInt(t,"dist",200)  
    call SetHandleInt(t,"change",3) 
    call SetHandleReal(t,"time",0)  
    call TimerStart(t, .03, true, function Firefly_Effects)
    
    set u = null
    set p = null
    set fire1 = null
    set fire2 = null
    set fire3 = null
    set fire4 = null
endfunction

//===========================================================================
function InitTrig_Firefly takes nothing returns nothing
    set gg_trg_Firefly = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Firefly, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Firefly, Condition( function Trig_Firefly_Conditions ) )
    call TriggerAddAction( gg_trg_Firefly, function Trig_Firefly_Actions )
endfunction

updated code, circle looks good, facing doesnt seem to change at all period, I figured I could start the untis a certain facing and increase it at a certain pase, and it may work as long as i get the correct initial facings good, but the facigns aren't changing, so that is bad
04-05-2006, 07:49 AM#4
blu_da_noob
Facing angle changes for a unit don't happen instantly, the unit turns around to face the specified angle over a period of time (it does not appear to be affected by the unit's turn speed).
04-05-2006, 01:37 PM#5
emjlr3
yea i figured that, anywho, i just decided to use balls instead ;)