angle function returning negative values

Mahrloc

New Member
Reaction score
5
i got a problem with the angle function:
Trigger:
  • Events
    • Unit - A unit starts the effect of an ability
    • Conditions
      • (Ability being cast) equal to push
    • Actions
      • Set pushTarget = (Target unit of ability being cast)
      • Set pushAngle = (Angle from (Position of (Casting unit)) to (Position of pushTarget))
      • Game - Display to (All players) the text: (String(pushAngle))
      • Game - Display to (All players) the text: (Name of pushTarget)
      • Game - Display to (All players) the text: (Name of Casting unit)

as you can see, it's a very simple trigger, but it returns a negative value when the angle between the points is greater than 180.
the units are always displayed correctly.
the ability push is based on channel.
maybe it's because i'm using the maximum map size(256x256)?
so why is it acting this way.
 

Mahrloc

New Member
Reaction score
5
til now the function always returned values in degrees, so how to change it back again?
 

cleeezzz

The Undead Ranger.
Reaction score
268
to degrees? theres a conversion function to change from rads to degrees. or multiply your angle by 180/pi
 

Mahrloc

New Member
Reaction score
5
the returned values are degrees but they are negative values, which makes the WE set them to 0 when i use them in a function that uses an angle.
anyway it worked properly in other maps so how can i turn it back? or is my map corrupted?
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
you can always add 360 degrees when it returns a negative value
which function you using anyway?
 

Mahrloc

New Member
Reaction score
5
i'm using the function mathematic - angle between two points... and i actually don't want to do that cause i know that it worked well in other maps
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Is there something making it negative? Like 0 - that angle or something? If you're using that function, it shouldn't be returning a negative value..
 

cleeezzz

The Undead Ranger.
Reaction score
268
JASS:
function AngleBetweenPoints takes location locA, location locB returns real
    return bj_RADTODEG * Atan2(GetLocationY(locB) - GetLocationY(locA), GetLocationX(locB) - GetLocationX(locA))
endfunction

thats angle between points converted from GUI to jass, as you can see, its supposed to return the result in degrees because atan2 gives radians but its multiplied by bj_RADTODEG which is 180/pi.
so your gui function should not be returning radians

and IIRC, that function can return negative degrees. ranging from -180 to 180.

unit facing however returns 0-360. also, IIRC, giving wc3 a negative degree would still work because it finds the equivalent degree on the 0-360 range if its negative.

hi vypur ^_^
 

vypur85

Hibernate
Reaction score
803
Guess I'll try to summarise everything from the above posts.

Angle between points return angle between -180 and 180.
Unit facing angle returns angle between 0 and 360.

If you don't want negative value, just conditionally convert it.

Code:
    Events
        Unit - A unit starts the effect of an ability
    Conditions
        (Ability being cast) equal to push 
    Actions
        Set pushTarget = (Target unit of ability being cast)
        Set pushAngle = (Angle from (Position of (Triggering unit)) to (Position of pushTarget))
        If then else..
           Condition
               pushAngle Less than 0.00
           Then - Actions
               Set pushAngle = pushAngle + 360.00
           Else - Actions
        Game - Display to (All players) the text: (String(pushAngle))
        Game - Display to (All players) the text: (Name of pushTarget)
        Game - Display to (All players) the text: (Name of Casting unit)

It's been mentioned above.
 

Mahrloc

New Member
Reaction score
5
i never noticed that the function returns negative values til now. but theres still one question to me:
if i use the negative angle in another function, the function uses 0 as angle. in my previous maps it truely worked but not in my current map. so my question is NOT how to fix it but why doesn't it work in this map?
thx for all the answers anyway :)
 

cleeezzz

The Undead Ranger.
Reaction score
268
it depends what function you put the angle into, maybe the one you're using doesn't know how to handle negative degrees?
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
add this line and it should work fine...
Trigger:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • your_variable Less than 0
    • Then - Actions
      • Set your_variable = (your_variable + 360)
    • Else - Actions


OR

make it an absolute value :)

thats if ur getting negative angles and not just negative numbers still in radians

and im pretty sure what is making ur negative angles is that the angle of the target is less than the angle of ur caster... so its setting the angle to negative the difference

and 2nd ^ what cleezzz said... doing that a lot lately :p... if ur trigger is using a real number
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
add this line and it should work fine...
Trigger:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • your_variable Less than 0
    • Then - Actions
      • Set your_variable = (your_variable + 360)
    • Else - Actions


OR

make it an absolute value :)

thats if ur getting negative angles and not just negative numbers still in radians

and im pretty sure what is making ur negative angles is that the angle of the target is less than the angle of ur caster... so its setting the angle to negative the difference

and 2nd ^ what cleezzz said... doing that a lot lately :p... if ur trigger is using a real number

He already knows how to solve the problem... He's asking why this happens..

I've used that for so long and I just realised. No idea why it worked for me either in my maps, still puzzled.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top