I'm using MoCo's Field of View library to check if selected units are within a cone of the field of view of my hero. Currently, I simply select all units within 600 range to a TempUnitGroup and then attempt to use the library to check if they are within the cone. If yes, deal some damage (just to test), if no (or is my hero), it sends a game message saying a unit is not in the cone.
For some reason, it affects every unit in a 600 range, except my hero and I can't figure out why. Can anyone help me spot my mistake? Thank you!
Variables:
DamageEventSource - Unit
DamageEventTarget - Unit
AngleTolleranceSH - Real
TempPoint - Point
TempUnitGroup - Unit Group
IsUnitInCone - Boolean
Trigger (relevant part in Actions):
Library:
For some reason, it affects every unit in a 600 range, except my hero and I can't figure out why. Can anyone help me spot my mistake? Thank you!
Variables:
DamageEventSource - Unit
DamageEventTarget - Unit
AngleTolleranceSH - Real
TempPoint - Point
TempUnitGroup - Unit Group
IsUnitInCone - Boolean
Trigger (relevant part in Actions):
Library:
JASS:
library FieldOfView
//*********************************************************************
//* =================================
//* FieldOfView 1.0.3 (by MoCo)
//* =================================
//*
//* This library provides 2 functions:
//*
//* - IsUnitInSightOfUnit(unit observer, unit target, real fieldOfView)
//* Checks if unit 'target' is within the field of view cone of unit 'observer'
//*
//* - IsUnitBehindUnit(unit unitToCheck, unit target, real fieldOfView)
//* Checks if unit 'unitToCheck' is behind unit 'target' within fieldOfView
//*
//*
//* Setup:
//* ======
//* Copy this library to your map.
//*
//*
//* Usage:
//* ======
//* Use the parameter fieldOfView to set the field of view (FoV) that should be used for the detection function.
//* The parameter needs to be set to half of the total field of view you want the unit to use.
//* For example, if you want a unit to have a total field of view cone of 180°, you need to use a parameter value of 90
//*
//* Note that the natural human field of view is about 135°, so you could use a value of 67.5 here.
//*
//* See the FovTester script for practical examples on how to use the functions.
//*
//*
//********************************************************************
function IsUnitInSightOfUnit takes unit observer, unit target, real fov returns boolean
local real face = GetUnitFacing(observer)
local real angle = bj_RADTODEG*Atan2(GetUnitY(target) - GetUnitY(observer), GetUnitX(target) - GetUnitX(observer))
return not (RAbsBJ(face - angle) > fov and RAbsBJ(face - angle - 360.) > fov)
endfunction
function IsUnitBehindUnit takes unit unitToCheck, unit target, real fov returns boolean
local real face = GetUnitFacing(target)
local real angle = bj_RADTODEG*Atan2(GetUnitY(target) - GetUnitY(unitToCheck), GetUnitX(target) - GetUnitX(unitToCheck))
return not (RAbsBJ(face - angle) > fov and RAbsBJ(face - angle - 360.) > fov)
endfunction
endlibrary