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

NOT a backstab spell

Status
Not open for further replies.
Level 11
Joined
Oct 9, 2015
Messages
721
Hello everyone, I would like to ask if anyone knows how can I detect if a unit is behind another, BUT I don't wanna know the difference between their facing angles, I wanna know if unit1 is in the "region" behind unit2, regardless of their facing angles.
 
You could calculate the distances to the center of this "region" if you mean that.
  • WhoLeads
    • Ereignisse
    • Bedingungen
    • Aktionen
      • Set LocCenter = (Center of (Playable map area))
      • Set Loc[1] = (Position of Unit[1])
      • Set Loc[2] = (Position of Unit[2])
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Condtions
          • (Distance between LocCenter and Loc[1]) greater as (Distance between LocCenter and Loc[2])
        • Then - Actions
          • -------- Unit 2 is behind --------
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between LocCenter and Loc[1]) Unequal (Distance between LocCenter and Loc[2])
            • Then - Actions
              • -------- Unit 1 is behind --------
            • Else - Actions
              • -------- Even --------
Edit: Hmm found a Problem works only if they walk to the region if the walk away you need to switch the first two results.
 
Level 11
Joined
Oct 9, 2015
Messages
721
a unit doesn't need to be facing the back of another to be behind it
Footman is behind Rifleman regardless of his facing angle
EDIT: Footman is behind RIFLEMAN'S BACK, regardles of the footman's facing angle.
2017-05-08.png
 
Last edited:
If that's what you are looking for, somekind of stealh mechanic.
Frontside.png

JASS:
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
 

Attachments

  • IsUnitBehind.w3x
    20 KB · Views: 25
Status
Not open for further replies.
Top