• 🏆 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!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

Back attack deals 2x damage

Level 13
Joined
Oct 28, 2019
Messages
488
Im trying makin a system I´ve saw in other game, that if a unit takes a hit in its back, it receive more damage. Im trying with damage engime with no sucess, using the facing angle, need help. This is what ´ve done until now.

The problem is when a unit facing angle is near the 340-350 and the other is near the zero, wich would need cause "back" damage, but this system cant read that

  • Facing Angle Copy
    • Events
      • Game - DamageEvent becomes Equal to 1.00
    • Conditions
      • (Unit-type of DamageEventSource) Not equal to Bowman
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Facing of DamageEventTarget) - (Facing of DamageEventSource)) Less than or equal to 90.00
          • ((Facing of DamageEventTarget) - (Facing of DamageEventSource)) Greater than or equal to 0.00
        • Then - Actions
          • Set VariableSet DamageEventAmount = ((2.50 x DamageEventAmount) - (Armor of DamageEventTarget))
          • Else - Actions
          • Set VariableSet DamageEventAmount = ((1.00 x DamageEventAmount) - (Armor of DamageEventTarget))
 
Last edited:

Uncle

Warcraft Moderator
Level 68
Joined
Aug 10, 2018
Messages
7,146
I'm assuming you aren't using a Bowman in your tests:
  • (Unit-type of DamageEventSource) Not equal to Bowman
Not equal to would cause problems, obviously.

Anyway, you can use this method I found in another thread, it seems to work fine:
  • Backstab
    • Events
      • Unit - A unit Takes damage
    • Conditions
    • Actions
      • Set VariableSet Backstab_Source_Angle = (Facing of (Damage source))
      • Set VariableSet Backstab_Target_Angle = (Facing of (Damage Target))
      • Set VariableSet Backstab_Threshold = 90.00
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Backstab_Target_Angle Greater than or equal to (Backstab_Threshold - 10.00)
        • Then - Actions
          • Set VariableSet Backstab_Source_Angle = (Backstab_Source_Angle + Backstab_Threshold)
          • Set VariableSet Backstab_Target_Angle = (Backstab_Target_Angle + Backstab_Threshold)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Backstab_Target_Angle Greater than or equal to (Backstab_Source_Angle - Backstab_Threshold)
          • Backstab_Target_Angle Less than or equal to (Backstab_Source_Angle + Backstab_Threshold)
        • Then - Actions
          • -------- It's a backstab! --------
          • Special Effect - Create a special effect attached to the overhead of (Damage source) using Abilities\Spells\Other\TalkToMe\TalkToMe.mdl
          • Special Effect - Destroy (Last created special effect)
        • Else - Actions
Backstab_Threshold is your Angle that determines what is considered a backstab. I added this variable to show how you could modify it.

Of course you will want to replace the Event/Event Responses with your Damage Engine variables.

Also, it would be more efficient to set Backstab_Threshold once at the start of the game or just delete it entirely and manually write the values throughout. Same goes for the subtraction in this line: (Backstab_Threshold - 10.00) since there's no reason to recalculate something that will never change.

 

Attachments

  • Backstab 1.w3m
    17.5 KB · Views: 1
Last edited:
Level 22
Joined
Feb 27, 2019
Messages
721
I prefer something like Makers most recent method in the thread posted by Uncle but I replaced angle between points for facing of damage source. One could argue angle between points is better than facing of damage source. Probably is.
  • Untitled Trigger 001
    • Events
      • Unit - A unit Takes damage
    • Conditions
    • Actions
      • Set VariableSet Real = (Acos((Cos(((Facing of (Damage source)) - (Facing of (Damage Target)))))))
      • Game - Display to (All players) the text: (String(Real))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Real Less than 45.00
        • Then - Actions
          • Game - Display to (All players) the text: Backstab!
        • Else - Actions
This is what Maker said for his method but that uses points.
"Using an angle of 90 makes the checked angle 180 degress, a semi circle. The attacker needs to be behind the target.

The closer to 0 you adjust the angle, the narrower the allowed angle will be. The width of the actual angle to be checked is always double the value you compare to in the condition."
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,239
Usual approach is to use cosine of the angle of the damaging unit with respect to the damaged unit relative to the facing of the damaged unit. If the damaging unit is in front of the damaged unit, then the cosine will be close to 1. If the damaging unit is directly behind the damaged unit then the cosine will be close to -1. Due to the cycling nature of cosine, it handles angle wrap-around perfectly.

Technically for computers this approach is slower than a proper conditional approach as trigonometric functions like cosine are quite slow to compute compared with tests. However, with JASS the overhead of the JASS virtual machine is so large compared with that of cosine that the simpler logic likely makes it faster.
 
Level 13
Joined
Oct 28, 2019
Messages
488
I prefer something like Makers most recent method in the thread posted by Uncle but I replaced angle between points for facing of damage source. One could argue angle between points is better than facing of damage source. Probably is.
  • Untitled Trigger 001
    • Events
      • Unit - A unit Takes damage
    • Conditions
    • Actions
      • Set VariableSet Real = (Acos((Cos(((Facing of (Damage source)) - (Facing of (Damage Target)))))))
      • Game - Display to (All players) the text: (String(Real))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Real Less than 45.00
        • Then - Actions
          • Game - Display to (All players) the text: Backstab!
        • Else - Actions
This is what Maker said for his method but that uses points.
"Using an angle of 90 makes the checked angle 180 degress, a semi circle. The attacker needs to be behind the target.

The closer to 0 you adjust the angle, the narrower the allowed angle will be. The width of the actual angle to be checked is always double the value you compare to in the condition."
Nice How I didnt think before in sin and cosine, nice math!!!!


I'm assuming you aren't using a Bowman in your tests:
  • (Unit-type of DamageEventSource) Not equal to Bowman
Not equal to would cause problems, obviously.
Why not equal to can cause problems???
 
Top