• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] IsUnitInSight (Field of View)

Status
Not open for further replies.
Level 13
Joined
May 24, 2005
Messages
609
Hey guys,

I'm searching for the smartest way to detect if a unit is within the field of view of another unit.

I'm currently using the following calcuation which seems to work fine:
JASS:
function IsUnitInSight takes unit observer, unit target returns boolean
    local real face = GetUnitFacing(observer)
    local real angle = bj_RADTODEG*Atan2(GetUnitY(observer)-GetUnitY(target), GetUnitX(observer)-GetUnitX(target))
    return not (RAbs(face-angle) < FIELD_OF_VIEW or RAbs(face-angle-360) < FIELD_OF_VIEW )
endfunction
Note that the FIELD_OF_VIEW constant is not the real field of view of the unit. The actual field of view would be 180 - 2x (FIELD_OF_VIEW-90)

My actual question is: is there any way to make this calculation more efficient in terms of performance?
In other words: do you see any potentials to optimize/streamline the function?
Other more efficient approaches are welcome as well.

I've also attached a small testmap.
If you know a better way for FoV detection, you could just replace the function in the test map and see if it works (make sure to test with all 4 villagers).
 

Attachments

  • FoVTest.JPG
    FoVTest.JPG
    56.1 KB · Views: 76
  • IsUnitInSight.w3m
    22.1 KB · Views: 42
Status
Not open for further replies.
Top