HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Angle = ???

10-12-2008, 10:34 PM#1
Joker
I wish I understood Trig... Something is wrong with my angle. The dummy alwys faces the same way and moves the same direction.

Collapse JASS:
scope PowerShot initializer Init

globals
    private constant string EFFECT = "Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl"

    private unit bool = null
endglobals

    private struct Power
        unit b
        timer t
        group g
        real c
        real x
        real y
        integer store
        integer lvl
        
        static method start takes unit b, real x, real y, real angle, integer lvl returns nothing
            local Power dat = Power.create()
            
              set dat.b = b
              set dat.t = NewTimer()
              set dat.g = NewGroup()
              set dat.lvl = lvl
              set dat.store = 0
              set dat.c = 0
              set dat.x = 30.*Cos(angle)
              set dat.y = 30.*Sin(angle)
            
            call SetTimerData(dat.t, dat)
            call TimerStart(dat.t, 0.04, true, function Power.callback)
        endmethod
        
        private static method callback takes nothing returns nothing
            local timer t = GetExpiredTimer()
            local Power dat = GetTimerData(t)
            local real x = GetUnitX(dat.b)
            local real y = GetUnitY(dat.b)
            
            if dat.c >= 1500. or dat.store >= 1+(dat.lvl*2) then
                call dat.destroy()
            endif
            
            call SetUnitX(dat.b, x+dat.c)
            call SetUnitY(dat.b, y+dat.c)
            call PingMinimap(dat.x+dat.c, dat.y+dat.c, 1.)
            
            call GroupEnumUnitsInRange(dat.g, x, y, 100., Condition(function Power.filter))
            if FirstOfGroup(dat.g) != null then
                set dat.store = dat.store + 1
                call UnitDamageTarget(dat.b, FirstOfGroup(dat.g), (dat.lvl*50)+100, false, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
                call DestroyEffect(AddSpecialEffectTarget(EFFECT, FirstOfGroup(dat.g), "chest"))
            endif
            
            set dat.c = dat.c + 60.
        endmethod
        
        private static method filter takes nothing returns boolean
            return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(bool)) and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false and GetWidgetLife(GetFilterUnit()) > 0.405 and IsPlayerInForce(GetOwningPlayer(GetFilterUnit()), My_Fighter)
        endmethod
        
        method onDestroy takes nothing returns nothing
            call KillUnit(.b)
            call ReleaseGroup(.g)
            call ReleaseTimer(.t)
        endmethod
    endstruct

//===========================================================================
private function Actions takes nothing returns nothing
    local unit a = GetTriggerUnit()
    local real ax = GetUnitX(a)
    local real ay = GetUnitY(a)
    local real x = GetLocationX(GetSpellTargetLoc())
    local real y = GetLocationY(GetSpellTargetLoc())
    local real angle = Atan2(ay-y, ax-x)
    local unit b = CreateUnit(GetOwningPlayer(a), 'n004', ax+75.*Cos(angle), ay+75.*Sin(angle), angle)
    
    call SetUnitPathing(b, false)
    call Power.start(b, ax, ay, angle, GetUnitAbilityLevel(a, 'A01F'))
    
    set bool = a
    set a = null
    set b = null
endfunction

//===========================================================================
private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A01F'
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    debug call TriggerRegisterPlayerUnitEvent( t, Player(0), EVENT_PLAYER_UNIT_SPELL_EFFECT, BOOLEXPR_TRUE )
    call TriggerRegisterPlayerUnitEvent( t, Player(2), EVENT_PLAYER_UNIT_SPELL_EFFECT, BOOLEXPR_TRUE )
    call TriggerRegisterPlayerUnitEvent( t, Player(5), EVENT_PLAYER_UNIT_SPELL_EFFECT, BOOLEXPR_TRUE )
    call TriggerAddCondition( t, Condition( function Conditions ) )
    call TriggerAddAction( t, function Actions )
endfunction

endscope
10-13-2008, 12:29 PM#2
Here-b-Trollz
Collapse JASS:
set b=CreateUnit(...,angle*bj_RADTODEG)

SetUnitX(dat.b,x+dat.x)
SetUnitY(dat.b,y+dat.y)
10-13-2008, 01:23 PM#3
Tide-Arc Ephemera
Do what Trollz said, put in a bj_RADTODEG. Atan2 - like all the rest of trig - gives you radians. For some ungodly reason, they've got so many trig or trig friendly functions but they also have a few degree functions lying about.
10-13-2008, 07:37 PM#4
Joker
Works fine now, thanks.