HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help me fix this move/dash/unit move like a missile spell

04-01-2010, 12:18 PM#1
shiFt...
I cant get the unit to stop moving or get it to move in the correct angle can somebody please help me in these areas.\
Collapse JASS:
scope MOVE initializer Init

    globals 
        private constant integer SPELL_ID = 'A045'
        private constant integer DUMMY = 'h01J'
        private constant integer DUMMY_SPELL = 'A02T'
        private hashtable ht = InitHashtable()
    endglobals
    
    private struct Data
        unit cs
        real x
        real y
        real x2
        real y2
        player p
        real dur
        integer ticks
        integer timeScaleTicks
        timer t
        group g
        real dmg
        real a
        real dist
        real x1
        real y1
        real targx
        real targy
    endstruct
    
    globals
        private unit U
        private unit DUM
        private Data D
        private real X
        private real Y
        private integer array TimerData
        private conditionfunc cf
        private group gg = CreateGroup()
    endglobals
    
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == SPELL_ID
    endfunction

  private function Effect2 takes nothing returns boolean
        set U = GetFilterUnit()
        if GetWidgetLife(U) > .405 and IsUnitEnemy(U,D.p) and not IsUnitInGroup(U,D.g) and IsUnitType(U,UNIT_TYPE_STRUCTURE) == false then
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\DevourMagic\\DevourMagicBirthMissile.mdl", U, "chest"))
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Feedback\\SpellBreakerAttack.mdl", U, "chest"))
            call UnitDamageTargetEx(D.cs,U, D.dmg, false, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
            
            set DUM = CreateUnit(D.p, DUMMY, GetWidgetX(U), GetWidgetY(U) ,0.00)
            call UnitAddAbility(DUM, DUMMY_SPELL)
            call UnitApplyTimedLife( DUM, 'BTLF', 1)
            call SetUnitAbilityLevel(DUM, DUMMY_SPELL,GetUnitAbilityLevel(D.cs, SPELL_ID))
            call IssueTargetOrder( DUM, "entanglingroots" ,U )
            
            call GroupAddUnit(D.g,U)
            
        endif
        return false
    endfunction
    
    private function Effects takes nothing returns nothing
        local Data d = LoadInteger(ht,GetHandleId(GetExpiredTimer()),0)
        if d.ticks > 0 then
            set d.ticks = d.ticks - 1
            if d.timeScaleTicks > 0 then
                set d.timeScaleTicks = d.timeScaleTicks - 1
            else
                set d.timeScaleTicks = 10000
            endif
            set D = d
            set d.x = GetUnitX(d.cs)
            set d.y = GetUnitY(d.cs)
            call SetUnitPosition(d.cs, d.x + 35, d.y + 35)
            call GroupEnumUnitsInRange(gg,d.x,d.y,175.,cf)
            return
        endif
       call PauseTimer(d.t)
        call GroupClear(d.g)
        call d.destroy()
    endfunction
    
    private function Actions takes nothing returns nothing
        local Data d = Data.create()
        set d.cs = GetTriggerUnit()
        set d.targx = GetSpellTargetX()
        set d.targy = GetSpellTargetY()
        set d.x2 = GetUnitX(d.cs)
        set d.y2 = GetUnitY(d.cs)
        set d.x1 = d.targx - d.x2
        set d.y1 = d.targy - d.y2
        set d.p = GetOwningPlayer(d.cs)
       
        
        set d.dist = SquareRoot(d.x1 * d.x1 + d.y1 * d.y1)
        set d.dur = d.dist/ 35
        set d.ticks = R2I(d.dur / .04)
        set d.timeScaleTicks = R2I(1. / .04)
        
        set d.dmg = 60 + ( 10* GetUnitAbilityLevel(d.cs,SPELL_ID))
        set d.a = AngleBetweenCoords( d.x, d.y, d.targx, d.targy)

       
       
        if d.t == null then
            set d.t = CreateTimer()
            call SaveInteger(ht,GetHandleId(d.t),0,d)
        endif
        if d.g == null then
            set d.g = CreateGroup()
        endif
        call TimerStart(d.t,.04,true,function Effects)
    endfunction

//---------------------------------------------------------------------------------------------------------
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger(  )
        local integer i = 0
        
        loop
            exitwhen i > 11
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set i = i + 1
        endloop

        call TriggerAddCondition( t, Condition( function Conditions ) )
        call TriggerAddAction( t, function Actions )
         set cf = Condition(function Effect2)
        set t = null
    endfunction
    
endscope
04-01-2010, 12:50 PM#2
Kueken
call SetUnitPosition(d.cs, d.x + 35, d.y + 35)
if you set x and y values + 35, you have a 45° movement always. You need to multiply this value with the sin and cos values of the angle:
call SetUnitPosition(d.cs, d.x + Cos(d.a)*35, d.y + Sin(d.a)*35)

However I recommend to store the sin and cos values instead of the angle to reduce calculations in the periodic function.
Collapse JASS:
            if d.timeScaleTicks > 0 then
                set d.timeScaleTicks = d.timeScaleTicks - 1
            else
                set d.timeScaleTicks = 10000
            endif
Whenever the ticks reach 0, they are set to 10000 again, how could it ever stop?