• 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.

Backstab

Status
Not open for further replies.
Donut, that won't work correctly. Facing of Triggering unit - Facing of attacking unit won't be returned in degrees. if one of the units are facing 10 degrees, and the other one 350. the result will be -340 or 340.

To do this correctly you will need angle calculation functions.

JASS:
function IsAngleBetweenAngles takes real angle, real angle1, real angle2 returns boolean
     local real x
        set angle=ModuloReal(angle,360)
        set angle1=ModuloReal(angle1,360)
        set angle2=ModuloReal(angle2,360)
        if (angle1>angle2) then
            set x=angle1
            set angle1=angle2
            set angle2=x
        endif
        if (angle2-angle1)>(angle1 - (angle2-360)) then
            set angle2=angle2-360
            if angle > 180 then
                set angle=angle-360
            endif
            return angle>=angle2 and angle<=angle1
        endif
     return (angle>=angle1) and (angle<=angle2)
    endfunction
Though it requires a little jass knowledge.
 
Level 27
Joined
Feb 22, 2006
Messages
3,052
Actually, I tested it and it works.
I'm pretty sure that if a degree is <0 and >360, then it will take the modulo.
If not you can take it anyways using
  • (((Facing of (Triggering unit)) - (Facing of (Attacking unit))) mod 360) Less than or equal to 90.00
  • (((Facing of (Triggering unit)) - (Facing of (Attacking unit))) mod 360) Greater than or equal to -90.00
--donut3.5--
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
I don't think you need to use angle functions... my way works fine:
JASS:
function IsUnitBehind takes unit Who, unit BehindWho, real Angle returns boolean
    local real d=GetUnitFacing(Who)-GetUnitFacing(BehindWho)
    if d>=180.0 then
        set d=d-360
    elseif d<=-180.0 then
        set d=d+360
    endif
    return (d<=Angle and d>=-Angle)
endfunction

The real "Angle" is just a more-or-less value of the angle difference. If this works, then I'm pretty sure that it's faster than calling angle functions and modulos.
 
Status
Not open for further replies.
Top