[General] The Angle of the Attack

Status
Not open for further replies.
Level 7
Joined
Feb 9, 2021
Messages
301
Can someone help me with the formula to determine from which angle the unit got attacked, please? I need an output between 0 and 360.
 
Level 24
Joined
Feb 27, 2019
Messages
789
Its not hard to determine the angle from which a unit is attacked.
Set Loc[1] = Position of attacking unit
Set Loc[2] = Position of attacked unit
Set Angle = Angle between Loc[2] and Loc[1]
call RemoveLocation(udg_Loc[1])
call RemoveLocation(udg_Loc[2])
Do you mean some way of determining the angle from the unit that is attacked in relation to where its facing and where the attacker is standing?
 
Last edited:
Level 7
Joined
Feb 9, 2021
Messages
301
Its not hard to determine the angle from which a unit is attacked.
Set Loc[1] = Position of attacking unit
Set Loc[2] = Position of attacked unit
Set Angle = Angle between Loc[2] and Loc[1]
call RemoveLocation(udg_Loc[1])
call RemoveLocation(udg_Loc[2])
Do you mean some way of determining the angle from the unit that is attacked in relation to where its facing and where the attacker is standing?
Sorry, forgot to mention. In relation to where it is facing. Also, I need it for X and Y coordinates.
 
Level 22
Joined
Dec 4, 2007
Messages
1,540
Not sure what you looking for, can you give an example?
Because, the function is already in the editor:
  • AngleTest
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Set VariableSet temp_real = (Facing of (Attacking unit))
      • Floating Text - Create floating text that reads (String(temp_real)) at (Position of (Attacking unit)) with Z offset 0.00, using font size 10.00, color (100.00%, 0.00%, 0.00%), and 0.00% transparency
      • Floating Text - Change (Last created floating text): Disable permanence
      • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
      • Floating Text - Change the fading age of (Last created floating text) to 3.00 seconds
The attacked event isn't really precise btw, you would be better off using Bribe's Damage System and fire angle calculations upon damage dealt.
I guess you are looking for backstab damage or front/side-only shield block?
 
Level 7
Joined
Feb 9, 2021
Messages
301
Not sure what you looking for, can you give an example?
Because, the function is already in the editor:
  • AngleTest
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Set VariableSet temp_real = (Facing of (Attacking unit))
      • Floating Text - Create floating text that reads (String(temp_real)) at (Position of (Attacking unit)) with Z offset 0.00, using font size 10.00, color (100.00%, 0.00%, 0.00%), and 0.00% transparency
      • Floating Text - Change (Last created floating text): Disable permanence
      • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
      • Floating Text - Change the fading age of (Last created floating text) to 3.00 seconds
The attacked event isn't really precise btw, you would be better off using Bribe's Damage System and fire angle calculations upon damage dealt.
I guess you are looking for backstab damage or front/side-only shield block?
I am looking to determine the angle of the attack relative to the attacked unit facing. So, backstab would be somewhere between 30 and 330 degrees, and front attack somewhere between 150 and 210. I need the angle from which the unit got attacked as the output (from 0 to 360). Ideally, an efficient formula in Jass. The only problem I have is with the math part.
 
Level 7
Joined
Feb 9, 2021
Messages
301
57.296*math.atan(TargetUnitY-UnitY,TargetUnitX-UnitX)
This does not take into account facing.

I am pretty sure you can set the OutputAngle to OutputAngle + -180 for the front then.
I don't need only back and front. As I said, I need an output from 0 to 360

Can someone help me, please? I don't believe no one had a similar problem. However, i can't find anything of the forum
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,272
  1. Work out the angle the attack came from. This is what [db]east has posted.
  2. Change frame of reference to be with respect to attacked unit's facing. This is done by subtracting the attacked units facing from the angle worked out in 1.
  3. Convert it to within the desired range. I think this is done using the real based modulus operation with a modulus of 360.
  4. If everything worked out the angle should be a number between 0 and 360 (not inclusive) as desired.
As an alternative to 3 and 4 for doing facing comparisons you might be able to use cosine or sine space for the comparison. This handles the cyclic nature of of the angular number space without needing to modulus or complicated comparisons.
 
Status
Not open for further replies.
Top