- 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:
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).
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
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).