• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Atan2 question

Status
Not open for further replies.
Hi guys, I want to use atan2, but i don't know how ... i saw the formula but i just can't use it right ... so i am using GetUnitFacing() instead, which is really bad =S

Can some1 help me out plz ?

JASS:
 private function Actions takes nothing returns nothing  
        local unit att = GetAttacker()  
        local player p = GetOwningPlayer(att)
        local real angle = GetUnitFacing(att)  //I want to use Atan2 but i dunno how ... plz help !!
        
        local unit ef
        local integer counter = 0
        local real distance = 100
        
        local real x
        local real y
        local group g = CreateGroup()
        local unit dum
        local unit vic
    
        loop
            exitwhen(counter > 6)
            set x = GetUnitX(att) + distance * Cos(angle * bj_DEGTORAD)
            set y = GetUnitY(att) + distance * Sin(angle * bj_DEGTORAD)
            set ef = CreateUnit(p, EFFECTID, x, y, 0.0)
            call UnitApplyTimedLife(ef, 'BTLF', 1.0)  
        
            //now to select purge and damage enemy units
            call GroupEnumUnitsInRange(g, GetUnitX(ef), GetUnitY(ef), AOE, Filter(null))
            loop  
                set vic = FirstOfGroup(g)  
                exitwhen (vic == null)  
                if IsUnitEnemy(vic, p) then
                    set dum = CreateUnit( p, DUMID, GetUnitX(ef), GetUnitY(ef), 0)  
                    call UnitApplyTimedLife(dum, 'BTLF', 2.5)  
                    call UnitAddAbility(dum, SPELLID)
                    call SetUnitAbilityLevel(dum, SPELLID, GetUnitAbilityLevel(att, BOOKID))
                    call IssueTargetOrder(dum, SPELLORDER, vic)    
                    call SetUnitState(vic, UNIT_STATE_LIFE, GetWidgetLife(vic) - (25 * GetUnitAbilityLevel(GetAttacker(), BOOKID)))   
                endif  
                call GroupRemoveUnit(g, vic)
            endloop
        
            set distance = distance + 100
            set counter = counter + 1
        endloop
    
        call DestroyGroup(g)
        set att = null  
        set ef = null
        set dum = null
        set g = null
        set p = null
    endfunction

EDIT EDIT EDIT

I managed to do something, but it is a little buggy =S Sometimes i create two lines of "eff" when i should only create one
JASS:
 local real angle = (180.0 / 3.14159) * Atan2(GetUnitY(GetTriggerUnit()) - GetUnitY(att), GetUnitX(GetTriggerUnit()) - GetUnitX(att))
Can any1 help me ? =S
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
You know, Atan and Atan2 return rads(no idea how the whole word is in english).
So either use Atan2BJ
JASS:
function AtanBJ takes real degrees returns real
    return Atan(degrees) * bj_RADTODEG
endfunction
or Multiply by bj_RADTODEG
 
Level 11
Joined
Apr 6, 2008
Messages
760
do u wanna get angle between 2 points? then u do like this Atan2(y-y2,x-x2)*57.27589

also dont use bj_RADTODEG its constant real bj_DEGTORAD=bj_PI/180.0 faster to do 3.14159/180 instead
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
You know, Atan and Atan2 return rads(no idea how the whole word is in english).
That's why he multiplies between 180/pi

And they're Radians.

Also, why are you all so insistent on degrees?

So either use Atan2BJ
Erm... no >>

do u wanna get angle between 2 points? then u do like this Atan2(y-y2,x-x2)*57.27589

You actually have it exactly backwards.

The angle between two x/y with Atan2 from x,y to x2,y2 is Atan2(y2-y,x2-x).
 
Level 14
Joined
Nov 20, 2005
Messages
1,156
do u wanna get angle between 2 points? then u do like this Atan2(y-y2,x-x2)*57.27589

also dont use bj_RADTODEG its constant real bj_DEGTORAD=bj_PI/180.0 faster to do 3.14159/180 instead

It's faster I'm betting to do *bJ_DEGTORAD than adding an extra division in there. *57.3... whatever would be faster, but harder to read and type, and bj_DEGTORAD is inlined anyway by Vex's optimizer, so no speed difference in release versions.

Hence, use *bj_DEGTORAD.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
That was not and still is not his problem :D
I wonder what did you mean by:
"Sometimes i create two lines of "eff" when i should only create one"
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
You are person number n who misspells my nick :D
Now I get why no one understood - your unit is ef and you say eff
Interesting.
Post whole trigger, at least.
P.s. and in your first post you say you create 2 lines of units , not 2 units at one spot.
 
You are person number n who misspells my nick :D
Sry about that :S

Post whole trigger, at least.
P.s. and in your first post you say you create 2 lines of units , not 2 units at one spot.

Yes. Because i initially create two units, the trigger seems to be activated for each of them, thus creating two lines :S
I don't think the other functions (Init, and Conditions) are important but i can post them if you need.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Well, probably not :D
Will sleep on it(most probably not)
Will get down to it when I get up early in the morning(absolutely not, maybe later)
:p
 
Status
Not open for further replies.
Top