• 🏆 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!

[Solved] Using a FieldOfView library for a cone spell - help needed

Status
Not open for further replies.
Level 4
Joined
Jan 20, 2022
Messages
26
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):
1646319043561.png


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
 

Attachments

  • 1646319030321.png
    1646319030321.png
    49.6 KB · Views: 6
Level 13
Joined
Jun 23, 2009
Messages
299
I think your issue is in the Custom Script in the loop, specifically with "udg_DamageEventTarget" in there, because it will always check if that specific target unit (which is not going to be the picked unit most of the time) is in the FOV so it will probably always turn true, try changing that one to "(Picked unit)" (GetEnumUnit() in JASS) and see if it works.
 
Level 4
Joined
Jan 20, 2022
Messages
26
I think your issue is in the Custom Script in the loop, specifically with "udg_DamageEventTarget" in there, because it will always check if that specific target unit (which is not going to be the picked unit most of the time) is in the FOV so it will probably always turn true, try changing that one to "(Picked unit)" (GetEnumUnit() in JASS) and see if it works.
How did I miss that?! THank you so much - works! :)
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Also, you can simply type 45.00 in the Custom script instead of referencing udg_AngleToleranceSH. And a nice optimization/safe move would be to store the (Picked unit) in a unit variable and reference that instead.
 
Level 4
Joined
Jan 20, 2022
Messages
26
Also, you can simply type 45.00 in the Custom script instead of referencing udg_AngleToleranceSH.
Ah, right you are :D When using help from here and there I tend to not think everyhthing through logically.

Thanks for the help guys :)
 
Status
Not open for further replies.
Top