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

Field of View [JASS]

Level 22
Joined
Aug 27, 2013
Messages
3,973
  • FoV Config
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- ---------------------------- --------
      • Set FoV_Observer = Peasant 0001 <gen>
      • -------- ---------------------------- --------
      • Set FoV_Target = Peasant 0002 <gen>
      • -------- ---------------------------- --------
      • Set FoV_VisionField = 67.50
      • -------- ---------------------------- --------
      • Set FoV_BehindField = 90.00
      • -------- ---------------------------- --------
JASS:
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 attacker, unit target, real fov returns boolean
    local real face = GetUnitFacing(target)
    local real angle = bj_RADTODEG*Atan2(GetUnitY(target)-GetUnitY(attacker),GetUnitX(target)-GetUnitX(attacker))
    return not(RAbsBJ(face-angle) > fov and RAbsBJ(face-angle-360) > fov)
endfunction

function Trig_Field_of_View_Actions takes nothing returns nothing
if IsUnitInSightOfUnit(udg_FoV_Observer, udg_FoV_Target, udg_FoV_VisionField) then
        call SetUnitVertexColor(udg_FoV_Observer, 255, 0, 0, 255)
    elseif IsUnitBehindUnit(udg_FoV_Target, udg_FoV_Observer, udg_FoV_BehindField) then
        call SetUnitVertexColor(udg_FoV_Observer, 0, 0, 255, 255)
    else
        call SetUnitVertexColor(udg_FoV_Observer, 255, 255, 255, 255)
    endif
endfunction

//===========================================================================
function InitTrig_Field_of_View takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( t, 0.25 )
    call TriggerAddAction( t, function Trig_Field_of_View_Actions )
endfunction

Attachments

  • Field of View.w3m
    16.9 KB · Views: 10
Last edited:
Top