Can you get the location of a projectile?

roaaaarrrr

New Member
Reaction score
33
I'm try to create a spell that does damage at different points of a projectile's motion. Say a unit shoots an arrow and I wanted to create a dummy unit at a point every 40th range the arrow moves? Then I could use that dummy to create whatever effect I want.
 

roaaaarrrr

New Member
Reaction score
33
Count the range in periodic function.

Care to elaborate...

What I tried to do is to calculate the distance between the caster and the target and divide this into segments. Then I use PolarProjectionBJ to periodically cause an effect in the same path that the projectile is using. I'm not quite done yet, so Im not sure if this works, but I thought there might be a better or easier way.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Care to elaborate...

What I tried to do is to calculate the distance between the caster and the target and divide this into segments. Then I use PolarProjectionBJ to periodically cause an effect in the same path that the projectile is using. I'm not quite done yet, so Im not sure if this works, but I thought there might be a better or easier way.

At the moment that is probably the most efficient way. Basically:
JASS:
originX + (maxDist/40)*Cos(angle)
originY + (maxDist/40)*Sin(angle)


Unless I am mistaken in what you're trying to do. =P
 

roaaaarrrr

New Member
Reaction score
33
I'm just going to post the trigger of what I have so far. Basically I have an invisible dummy unit fire one frost arrow from the caster to the target. I want there to be several explosions of frost (frost novas) in between the caster and target following the path of the frost arrow. I havent had time to clean everything up, so there are probably still leaks and other issues, but it is at least compiling clean. The only issue is that the novas are not being created at all, so I have no idea if they are being created in the correct location.

JASS:
scope FrostArrow

    globals
        constant integer FA_ArrowUnitRaw = 'h01H' 
        constant integer FA_Raw = 'A0A9'
        constant integer FA_FNRaw = 'A0AF'
        constant integer FA_DummyRaw = 'h01I'
        constant real FA_Delay = 0.20
        constant real FA_DmgConst = 25.
        constant real FA_DmgLvl = 75.
    endglobals
        
        struct Arrow
            unit arr
            unit t
            unit u
        endstruct

function FA_Arrow takes nothing returns nothing
    local timer tim = GetExpiredTimer()
    local unit d
    local real dist
    local integer step = 0
    local real maxsteps
    local Arrow Data1 = GetTimerData(tim)
    local location steploc
    local location endloc = GetSpellTargetLoc()
    local real x = GetUnitX(Data1.u)
    local real y = GetUnitY(Data1.u)
    local real endX = GetLocationX(endloc)
    local real endY = GetLocationY(endloc)
    local real ang = Atan2(endY-y, endX - x)
    set dist = DistanceBetweenPoints(GetUnitLoc(Data1.u), GetUnitLoc(Data1.t))
    set maxsteps = dist/60.
    loop
        set d = CreateUnitAtLoc(GetOwningPlayer(Data1.arr), FA_DummyRaw, PolarProjectionBJ(steploc, 60., ang), 270)
        set steploc = PolarProjectionBJ(steploc, 60., ang)
        call UnitApplyTimedLife(d, 'BTLF', 0.5)
        call UnitAddAbility(d, FA_FNRaw)
        call SetUnitAbilityLevel(d, FA_FNRaw, GetUnitAbilityLevel(Data1.u, FA_Raw))
        call IssueTargetOrder(d, "frostnova", d)
        set step = step + 1
        exitwhen step > maxsteps
    endloop
    call UnitDamageTarget(Data1.arr, Data1.t, (FA_DmgLvl + FA_DmgConst * GetUnitAbilityLevel(Data1.u, FA_Raw)), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_COLD, WEAPON_TYPE_WHOKNOWS)
    call RemoveUnit(Data1.arr)
    call ReleaseTimer( GetExpiredTimer() )
    set d = null 
    set tim = null
endfunction

function FA_Conds takes nothing returns boolean
    return GetSpellAbilityId() == FA_Raw
endfunction

function FA_Acts takes nothing returns nothing
    local Arrow Data1 = Arrow.create()
    local location p
    local location tp
    local timer tim
    set Data1.t = GetSpellTargetUnit()
    set Data1.u = GetTriggerUnit()
    set p = GetUnitLoc(Data1.u)
    set tp = GetUnitLoc(Data1.t)
    set Data1.arr = CreateUnit(GetOwningPlayer(Data1.u), FA_ArrowUnitRaw, GetLocationX(p), GetLocationY(p), AngleBetweenPoints( p, tp))
    call UnitApplyTimedLife(Data1.arr, 'BTLF', 2)
    set tim = NewTimer()
    
    call IssueTargetOrder(Data1.arr, "attackonce", Data1.t)
    
    call SetTimerData(tim, Data1)
    
    call TimerStart(tim, 0.25, true, function FA_Arrow)
    
    call RemoveLocation(p)
    call RemoveLocation(tp)
endfunction
endscope

function InitTrig_FrostArrow takes nothing returns nothing
    set gg_trg_FrostArrow = CreateTrigger()
    call PreloadAbility(FA_Raw)
    call PreloadAbility(FA_FNRaw)
    call TriggerRegisterAnyUnitEventBJ( gg_trg_FrostArrow, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition(gg_trg_FrostArrow, Condition(function FA_Conds))
    call TriggerAddAction(gg_trg_FrostArrow, function FA_Acts)
endfunction


Any help would be greatly appreciated :)
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Add a unit model to the dummy unit so that you can check the positions of the dummies being spawned. This will allow you to know first if your spawning code is correct.
 

roaaaarrrr

New Member
Reaction score
33
Figured that part out... i forgot to define an initial value for steploc. So its creating units just as intended, however they are always being created in a straight horizontal line to the right of my hero. Any ideas on what formula will give me the correct angle between caster and target?
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
You are better off using a projectile system.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top