function IsUnitBehind takes unit main, unit u returns boolean
local real xInFront = GetUnitX(main) + 1 * Cos(bj_DEGTORAD * GetUnitFacing(main))
local real yInFront = GetUnitY(main) + 1 * Sin(bj_DEGTORAD * GetUnitFacing(main))
local real Angle1 = bj_RADTODEG * Atan2(GetUnitY(main) - yInFront, GetUnitX(main) - xInFront)
local real Angle2 = bj_RADTODEG * Atan2(GetUnitY(u) - yInFront, GetUnitX(u) - xInFront)
local real Angle
// Make Angel1 +
if Angle1 < 0.00 then
set Angle1 = Angle1 + 360.00
else
endif
// Make Angel2 +
if Angle2 < 0.00 then
set Angle2 = Angle2 + 360.00
else
endif
// Simplfy Calculation at 0° line if needed
if ( Angle2 >= 270.00 and Angle1 < 90.00 ) then
set Angle1 = 360.00 + Angle1
else
if ( Angle1 >= 270.00 and Angle2 < 90.00) then
set Angle2 = 360.00 + Angle2
else
endif
endif
set Angle = Angle1 - Angle2
// call DisplayTimedTextToForce( GetPlayersAll(), 5.00, R2S(Angle1) + " / " +R2S(Angle2) + "->"+R2S(Angle) )
return ( Angle >= -80.00 and Angle <= 80.00 )
endfunction