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

[Trigger] Check if a unit is in the field of view of any other unit.

Status
Not open for further replies.
Level 10
Joined
Feb 19, 2006
Messages
237
I have what appears to be a basic trigger which checks if a unit is in the field of view of any other unit. If they are NOT in anyone's field of view the variable "visible" is set to 0 and the text "undetected" is displayed. The trigger does not seem to work. It displays detected /undetected randomly. Here is the code.

  • Untitled Trigger 001
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units within 400.00 of (Position of Baskiran Bandit 0017 <gen>)) and do (Actions)
        • Loop - Actions
          • Set Point[1] = (Position of Baskiran Bandit 0017 <gen>)
          • Set Point[2] = (Position of (Picked unit))
          • Set Real[1] = (Angle from Point[1] to Point[2])
          • Set Real[2] = (Facing of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • Real[1] Greater than or equal to (Real[2] - 90.00)
                  • Real[1] Less than or equal to (Real[2] + 90.00)
            • Then - Actions
              • -------- behind (invisible) --------
              • Set visible = 0
            • Else - Actions
              • -------- in front (visible) --------
              • Set visible = 1
          • Custom script: call RemoveLocation (udg_Point[2])
          • Custom script: call RemoveLocation (udg_Point[1])
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • visible Equal to 0
        • Then - Actions
          • Game - Display to (All players) the text: undetected
        • Else - Actions
          • Game - Display to (All players) the text: DETECTED
 
Level 4
Joined
Feb 22, 2012
Messages
74
I remember having some problems with my map a long time ago, basically it stems from how angles are calculated in War3:

"Angle between points" has a range of -180 to 180
"Facing angle of unit" has a range of 0 to 360

So you have to use the Modulo operation to synch them up. I am not sure how anymore, someone here will know though.

But, there has been a better solution posted already.

Here fixed some more leaks in your trigger. Any time you use a unit group that has not been assigned a variable, it will leak. Also, your Point[1] calculation can be done outside the unit group actions since it will not change between picked units.

  • Untitled Trigger 001
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
  • Set Point[1] = (Position of Baskiran Bandit 0017 <gen>)
  • Set Group = (Units within 400.00 of Point[1])
    • Unit Group - Pick every unit in Group and do (Actions)
      • Loop - Actions
        • Set Point[2] = (Position of (Picked unit))
        • Set Real[1] = (Angle from Point[1] to Point[2])
        • Set Real[2] = (Facing of (Picked unit))
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • And - All (Conditions) are true
              • Conditions
                • Real[1] Greater than or equal to (Real[2] - 90.00)
                • Real[1] Less than or equal to (Real[2] + 90.00)
          • Then - Actions
            • -------- behind (invisible) --------
            • Set visible = 0
          • Else - Actions
            • -------- in front (visible) --------
            • Set visible = 1
        • Custom script: call RemoveLocation (udg_Point[2])
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • visible Equal to 0
      • Then - Actions
        • Game - Display to (All players) the text: undetected
      • Else - Actions
        • Game - Display to (All players) the text: DETECTED
  • Custom script: call RemoveLocation (udg_Point[1])
  • Custom script: call DestroyGroup (udg_Group)
 
Level 10
Joined
Feb 19, 2006
Messages
237
This one still doesn't work.

How come this one still doesn't work. Again, it is completely random, sometimes it says "undetected" when im right in front of a unit, sometimes it says detected when i'm behind him, sometimes it says both randomly.

What is wrong with this trigger. (p.s don't worry about leaks, i'll take care of those after i actually figure out how to work this)

  • Line of Signt System
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units within 300.00 of (Position of Footman 0000 <gen>)) and do (Actions)
        • Loop - Actions
          • Set Point[1] = (Position of (Picked unit))
          • Set Point[2] = (Position of Footman 0000 <gen>)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Acos((Cos(((Facing of (Picked unit)) - (Angle from Point[1] to Point[2])))))) Less than or equal to 40.00
            • Then - Actions
              • Game - Display to (All players) the text: detected
            • Else - Actions
              • Game - Display to (All players) the text: undetected
 
Level 17
Joined
Jul 17, 2011
Messages
1,863
(Acos((Cos(((Facing of (Picked unit)) - (Angle from Point[1] to Point[2])))))) Less than or equal to 40.00
lol?? do you know that the cos of the angle of the picked unit will be ALWAYS a number less than one in your case its less than 40.

anyways here is a good way of calculating if a line between two points is obstructed

first you have to define what your obstructions will be: terrain units destructibles.
lets look at terrain because its the hardest. i think this can only come in handy if you are making a first person map otherwise if you are not this is useless
ok so use distance between points to check the distance between the two targets then divide by two and get the terrain height with this function "GetLocationZ[your unit's position] then use if/then/else to check if it is higher than the Z at the position of you unit if it IS then set a boolean or something
ok no time to explain more booty bay fishing tournament is about to start :DD
 
Level 10
Joined
Feb 19, 2006
Messages
237
lol?? do you know that the cos of the angle of the picked unit will be ALWAYS a number less than one in your case its less than 40.

anyways here is a good way of calculating if a line between two points is obstructed

first you have to define what your obstructions will be: terrain units destructibles.
lets look at terrain because its the hardest. i think this can only come in handy if you are making a first person map otherwise if you are not this is useless
ok so use distance between points to check the distance between the two targets then divide by two and get the terrain height with this function "GetLocationZ[your unit's position] then use if/then/else to check if it is higher than the Z at the position of you unit if it IS then set a boolean or something
ok no time to explain more booty bay fishing tournament is about to start :DD

I'm sorry but I think you misunderstood my question :/.
Have fun watching booty bay.
 
Level 4
Joined
Feb 22, 2012
Messages
74
angle "from point[1] to point[2]" is backwards it is checking from the picked unit, not your footman.

so it is basically checking if the 2 units are facing the same 80-degree cone.

try from pt2 to pt1

also, set your "position of footman" point OUTSIDE of the unit group loop, it saves you some processing. Not a big deal but it is pointless to define the same point 10 times when it will remain constant.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
  • Untitled Trigger 002
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set u1 = Paladin 0003 <gen>
      • Set p1 = (Position of u1)
      • Set b1 = False
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units within 300.00 of p1) and do (Actions)
        • Loop - Actions
          • Set u2 = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • b1 Equal to False
              • u1 Not equal to u2
              • (u2 is alive) Equal to True
              • (u2 is A structure) Equal to False
            • Then - Actions
              • Set r1 = (Facing of u2)
              • Set p2 = (Position of u2)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Acos((Cos((r1 - (Angle from p2 to p1)))))) Less than 45.00
                • Then - Actions
                  • Set b1 = True
                • Else - Actions
              • Custom script: call RemoveLocation(udg_p2)
            • Else - Actions
      • Custom script: call RemoveLocation(udg_p1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • b1 Equal to True
        • Then - Actions
          • Game - Display to Player Group - Player 1 (Red) the text: Detected
        • Else - Actions
          • Game - Display to Player Group - Player 1 (Red) the text: Hidden
Using a value of 45 makes the angle to be checked be 90°, which is still quite narrow.
 
Last edited:
Level 10
Joined
Feb 19, 2006
Messages
237
IsaacNewbton,

I tried your suggestion, it didn't do anything. Besides, Maker is calculating the angle from the same points as I. And I'm planning on optimizing the trigger AFTER i get it to work first, but i do appreciate the heads up bro.

Maker,

Besides the conditions which check if the picked unit is a live and not a structure and stuff, your trigger is no different than mine. Have you tested yours? Does it work in game? If so I would not understand why yours would work and mine would not work.
 
IsaacNewton was right about your problem. You should check out this post and use the first function quoted. a1 can be the facing of your unit, and a2 the angle between the two units. It will return an angle between 0 and 180 where obviously, 0 is right in front and 180 is behind.

EDIT: i noticed there is a GUI version at the bottom incase the JASS code turned you off.
 
Status
Not open for further replies.
Top