HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Making a unit circle around another unit

01-07-2009, 06:26 PM#1
azwraith_ftL
Basically, I'm trying to make a dummy unit circle around a specific unit when a spell is cast. This would become something similar to the ladder ability Sphere, however the dummy unit only completes a full circle. So far everything works OK - I cast the spell and the unit circles around the caster, however the problem occurs when he moves. The dummy unit moves out of it's course and starts to circle somewhere else, not around the caster, while I've limited it's maximum range to X. Here's the code, if someone can find a sollution with my crappy math calculations:

Collapse JASS:
scope a initializer Init 

globals
    private constant integer AID_RAW = 'A000'
    private constant integer UID_EFFECT = 'h003'
    private constant string  SFX_EFFECT = "Abilities\\Weapons\\FaerieDragonMissile\\FaerieDragonMissile.mdl"
endglobals

    private function AOE takes unit cast, integer lvl returns real
        return 1.
    endfunction
    private function DAMAGE takes unit cast, integer lvl returns real
        return 1.
    endfunction

globals
    public trigger trig = CreateTrigger()
endglobals

private struct Data
    unit cast
    unit dum
    real dps
    real xx
    real yy
    integer i = 1
    effect sfx
    
    static method create takes unit a, unit b returns Data
        local Data d = Data.allocate()
        set d.cast = a
        set d.dum  = b
        set d.sfx = AddSpecialEffectTarget(SFX_EFFECT, d.dum, "chest")
        return d
    endmethod
    
    method onDestroy takes nothing returns nothing
        set .cast = null
        set .dum  = null
    endmethod
endstruct

private function Conditions takes nothing returns boolean  
    return GetSpellAbilityId() == AID_RAW
endfunction

private function Callback takes nothing returns boolean
    local Data d = TT_GetData()
    // tried moving the dummy right next to the caster, if that would help.. no effect
    call SetUnitX(d.dum, GetUnitX(d.cast)) 
    call SetUnitY(d.dum, GetUnitY(d.cast))
    set d.xx = GetUnitX(d.cast) + 150. * Cos(((GetUnitFacing(d.dum) + (8. * d.i)) * bj_DEGTORAD))
    set d.yy = GetUnitX(d.cast) + 150. * Sin(((GetUnitFacing(d.dum) + (8. * d.i)) * bj_DEGTORAD))
    set d.i = d.i + 1
    if d.i > 45 then
        set d.i = 1
    endif
    call SetUnitX(d.dum, d.xx)
    call SetUnitY(d.dum, d.yy)
    call SetUnitFlyHeight(d.dum, GetRandomReal(20., 100.), 0.)
    return false
endfunction
    

private function Actions takes nothing returns nothing
    local Data d = Data.create(GetTriggerUnit(), CreateUnit(GetOwningPlayer(GetTriggerUnit()), UID_EFFECT, GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), 0.))
    call UnitAddAbility(d.dum, 'Amrf')
    call UnitRemoveAbility(d.dum, 'Amrf')
    call TT_Start(function Callback, d)
endfunction

private function Init takes nothing returns nothing
    call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(trig, Condition(function Conditions))
    call TriggerAddAction(trig, function Actions)
endfunction

endscope

The error should be here, in the calculation of the new X and Y:

Collapse JASS:
    set d.xx = GetUnitX(d.cast) + 150. * Cos(((GetUnitFacing(d.dum) + (8. * d.i)) * bj_DEGTORAD))
    set d.yy = GetUnitX(d.cast) + 150. * Sin(((GetUnitFacing(d.dum) + (8. * d.i)) * bj_DEGTORAD))
    set d.i = d.i + 1
    if d.i > 45 then
        set d.i = 1
    endif
    call SetUnitX(d.dum, d.xx)
    call SetUnitY(d.dum, d.yy)
01-07-2009, 07:48 PM#2
V@dim
set d.xx = GetUnitX(d.cast) + 150. * Cos(((GetUnitFacing(d.dum) + (8. * d.i)) * bj_DEGTORAD))
set d.yy = GetUnitY(d.cast) + 150. * Sin(((GetUnitFacing(d.dum) + (8. * d.i)) * bj_DEGTORAD))
set d.i = d.i + 1
if d.i > 45 then
set d.i = 1
endif
call SetUnitX(d.dum, d.xx)
call SetUnitY(d.dum, d.yy)

=)
01-07-2009, 07:53 PM#3
azwraith_ftL
/facepalm

Thank you.