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

[Trigger] Unit facing angle help

Status
Not open for further replies.
Level 8
Joined
Apr 30, 2009
Messages
338
This trigger is supposed to cast on units up to 800 range in a 60-degree arc in front of the caster. The problem is it won't work on units that are below and to the left of the caster, no matter if the caster is facing them or not.

It's definitely the angle check because the spell always works if I just have it cast on all units in 800 range.

I even tried setting the "Facing minus 30" to "Facing plus 330" and it still did not work.

Here is the part of the spell that's fucking up, and below it is the full spell for context.

  • Infernal Wave 1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to SRC.A1 - Infernal Wave [W]
    • Actions
      • Set temp_point[0] = (Position of (Triggering unit))
      • Set temp_group = (Units within 800.00 of temp_point[0] matching ((((Matching unit) is alive) Equal to True) and ((((Matching unit) belongs to an ally of (Owner of (Triggering unit))) Equal to False) and (((Matching unit) is Mechanical) Equal to False))))
      • Unit Group - Pick every unit in temp_group and do (Actions)
        • Loop - Actions
          • Set temp_point[1] = (Position of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Angle from temp_point[0] to temp_point[1]) Less than or equal to ((Facing of (Triggering unit)) + 30.00)
              • (Angle from temp_point[0] to temp_point[1]) Greater than or equal to ((Facing of (Triggering unit)) - 30.00)
            • Then - Actions
              • Set temp_point[2] = (temp_point[0] offset by 50.00 towards (Angle from temp_point[0] to temp_point[1]) degrees)
              • Unit - Create 1 infernalwave for (Owner of (Triggering unit)) at temp_point[2] facing (Angle from temp_point[0] to temp_point[1]) degrees
              • Custom script: call RemoveLocation( udg_temp_point[1] )
              • Custom script: call RemoveLocation( udg_temp_point[2] )
  • Infernal Wave 1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to SRC.A1 - Infernal Wave [W]
    • Actions
      • Set current_hashtable = H_InfernalWave
      • Set current_group = InfernalWaveMissles
      • Set SpellDamage_Base = 45.00
      • Set SpellDamage_Level = 35.00
      • Set Spellpower_Coefficient = 0.70
      • Set temp_point[0] = (Position of (Triggering unit))
      • Set temp_group = (Units within 800.00 of temp_point[0] matching ((((Matching unit) is alive) Equal to True) and ((((Matching unit) belongs to an ally of (Owner of (Triggering unit))) Equal to False) and (((Matching unit) is Mechanical) Equal to False))))
      • Unit Group - Pick every unit in temp_group and do (Actions)
        • Loop - Actions
          • Set temp_point[1] = (Position of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Angle from temp_point[0] to temp_point[1]) Less than or equal to ((Facing of (Triggering unit)) + 30.00)
              • (Angle from temp_point[0] to temp_point[1]) Greater than or equal to ((Facing of (Triggering unit)) - 30.00)
            • Then - Actions
              • Set temp_point[2] = (temp_point[0] offset by 50.00 towards (Angle from temp_point[0] to temp_point[1]) degrees)
              • Unit - Create 1 infernalwave for (Owner of (Triggering unit)) at temp_point[2] facing (Angle from temp_point[0] to temp_point[1]) degrees
              • Custom script: call RemoveLocation( udg_temp_point[1] )
              • Custom script: call RemoveLocation( udg_temp_point[2] )
              • Hashtable - Save ((SpellDamage_Base + (SpellDamage_Level x (Real((Level of (Ability being cast) for (Triggering unit)))))) + (Spellpower_Coefficient x (Load 100 of (Key (Triggering unit)) from H_Spellpower))) as (Key damage) of (Key (Last created unit)) in current_hashtable
              • Hashtable - Save Handle Of(Triggering unit) as (Key caster) of (Key (Last created unit)) in current_hashtable
              • Hashtable - Save Handle Of(Picked unit) as (Key target) of (Key (Last created unit)) in current_hashtable
              • Hashtable - Save 600.00 as (Key speed) of (Key (Last created unit)) in current_hashtable
              • Hashtable - Save 30.00 as (Key speedmod) of (Key (Last created unit)) in current_hashtable
              • Unit Group - Add (Last created unit) to current_group
            • Else - Actions
          • Unit Group - Remove (Picked unit) from temp_group
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Infernal Wave 2 <gen> is on) Equal to False
            • Then - Actions
              • Trigger - Turn on Infernal Wave 2 <gen>
            • Else - Actions
      • Custom script: call RemoveLocation( udg_temp_point[0] )
      • Custom script: call DestroyGroup( udg_temp_group )
      • Custom script: set udg_current_hashtable = null
      • Custom script: set udg_current_group = null
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
Angle Between Points returns values between -180 and 180, while Facing Angle of unit returns values between 0 and 360. And while -90 and 270 is technically the same angle, it won't pass your check. Use modulo(angle between points, 360), to convert the +-180 range to 0-360 range.
Also, if angle between points is 10 degrees and facing angle is 350, it is a 20 degrees differenc and it would fail again. So what you really need is to substract the angles from each other, shift it to 0-360 range(using modulo) and then test whether the result is <30 or >330
 
Level 8
Joined
Apr 30, 2009
Messages
338
Wow this is a lot harder than I though, there's always one fucking angle that it doesn't work at. There has to be an easier way
 
Level 8
Joined
Apr 30, 2009
Messages
338
Instead of using mod I just changed facing of triggering unit to angle between loc of triggering unit and point 800 in front of triggering unit. That way it's all in [-180,180] but it still messes up across the west axis. I tried figuring something out with abs value but then it would mess across the east-west axis.

  • Infernal Wave 1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to SRC.A1 - Infernal Wave [W]
    • Actions
      • Set current_hashtable = H_InfernalWave
      • Set current_group = InfernalWaveMissles
      • Set SpellDamage_Base = 45.00
      • Set SpellDamage_Level = 35.00
      • Set Spellpower_Coefficient = 0.70
      • Set temp_point[0] = (Position of (Triggering unit))
      • Set temp_point[1] = (temp_point[0] offset by 800.00 towards (Facing of (Triggering unit)) degrees)
      • Set temp_real[0] = (Angle from temp_point[0] to temp_point[1])
      • Custom script: call RemoveLocation( udg_temp_point[1] )
      • Set temp_group = (Units within 800.00 of temp_point[0] matching ((((Matching unit) is alive) Equal to True) and ((((Matching unit) belongs to an ally of (Owner of (Triggering unit))) Equal to False) and (((Matching unit) is Mechanical) Equal to False))))
      • Unit Group - Pick every unit in temp_group and do (Actions)
        • Loop - Actions
          • Set temp_point[1] = (Position of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Angle from temp_point[0] to temp_point[1]) Less than or equal to (temp_real[0] + 30.00)
              • (Angle from temp_point[0] to temp_point[1]) Greater than or equal to (temp_real[0] - 30.00)
            • Then - Actions
              • Set temp_point[2] = (temp_point[0] offset by 50.00 towards (Angle from temp_point[0] to temp_point[1]) degrees)
              • Unit - Create 1 infernalwave for (Owner of (Triggering unit)) at temp_point[2] facing (Angle from temp_point[0] to temp_point[1]) degrees
              • Custom script: call RemoveLocation( udg_temp_point[1] )
              • Custom script: call RemoveLocation( udg_temp_point[2] )
              • Hashtable - Save ((SpellDamage_Base + (SpellDamage_Level x (Real((Level of (Ability being cast) for (Triggering unit)))))) + (Spellpower_Coefficient x (Load 100 of (Key (Triggering unit)) from H_Spellpower))) as (Key damage) of (Key (Last created unit)) in current_hashtable
              • Hashtable - Save Handle Of(Triggering unit) as (Key caster) of (Key (Last created unit)) in current_hashtable
              • Hashtable - Save Handle Of(Picked unit) as (Key target) of (Key (Last created unit)) in current_hashtable
              • Hashtable - Save 600.00 as (Key speed) of (Key (Last created unit)) in current_hashtable
              • Hashtable - Save 30.00 as (Key speedmod) of (Key (Last created unit)) in current_hashtable
              • Unit Group - Add (Last created unit) to current_group
            • Else - Actions
          • Unit Group - Remove (Picked unit) from temp_group
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Infernal Wave 2 <gen> is on) Equal to False
            • Then - Actions
              • Trigger - Turn on Infernal Wave 2 <gen>
            • Else - Actions
      • Custom script: call RemoveLocation( udg_temp_point[0] )
      • Custom script: call DestroyGroup( udg_temp_group )
      • Custom script: set udg_current_hashtable = null
      • Custom script: set udg_current_group = null
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
not exactly, it also shifts the number to range of 0-359 (even if it is negative)

EDIT: explanation of the formula: the difference( facing - angle between points) is actually the difference betweem the two angles. The modulo shifts this value to the range of 0-359. And lastly, if the angle is 0-30 (picked unit is up to 30 degrees left from caster) or 0 to -30, which equals 330-359 ( 30 degrees right of the caster), it is in the cone

Also, put your triggers in
tag, they are totally messing up the formating of the site (way too long)
 
Status
Not open for further replies.
Top