Facing Angle Loophole

Cheddar

This is the way it was meant to be.
Reaction score
126
Okay, here is the problem.

In a normal GUI triggered backstab spell, the obvious way to detect if a unit is behind another is by comparing facing angles -- for instance, if the difference between the two is between -30 and 30.

Attacker has facing angle of 50.
Attacked unit has a facing angle of 59.

Trigger goes off.

So, what's the problem? As AceHart kindly pointed out in one thread:

Attacker has a facing angle of 1.
Attacked unit has a facing angle of 359.

Trigger fails to activate, even though the two units are near-perfectly lined up.

I have used the Search button, never fear, yet I failed to find any threads returning my query and an answer to it. If you can pose a solution to this problem, I would greatly appreciate it. And +rep.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
Given all the threads that asked this, there must be one at least with something usable...

My personal favorite:
JASS:
function IsInBack takes unit unit1,unit unit2,real angle returns boolean
    local real a = 2 * ModuloReal(bj_RADTODEG * Atan2(GetUnitY(unit2) - GetUnitY(unit1),GetUnitX(unit2) - GetUnitX(unit1)) - GetUnitFacing(unit2), 360.0)
    return a <= angle or 720.0 - a <= angle
endfunction


Returns true if unit1 stands in the back of unit2 within some limit (40 degrees for example).

Note the "stands"! It returns true if unit1 stands in unit2's back, looking at unit2's back is not required.
 
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