• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Spell] Valid Backstab

Status
Not open for further replies.

sentrywiz

S

sentrywiz

Hi all.

How would I make a valid backstab? I tried with facing of target of ability unit, but I don't really know enough trigonometry and angles to make it. I know its sinus cosine something.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
JASS:
function IsAttackBackstab takes unit attacker, unit victim returns boolean
    local real x1=GetUnitX(victim)
    local real y1=GetUnitY(victim)
   
    local real x2=GetUnitX(attacker)
    local real y2=GetUnitY(attacker)
   
    local real victimFacing=GetUnitFacing(victim)*bj_DEGTORAD
    local real attackAngle=Atan2(y2-y1,x2-x1)
   
    set attackAngle=Acos(Cos(attackAngle-victimFacing))
   
    return (attackAngle*bj_RADTODEG)>120
endfunction

Dunno why it works though, I already forgot.
 

sentrywiz

S

sentrywiz

JASS:
function IsAttackBackstab takes unit attacker, unit victim returns boolean
    local real x1=GetUnitX(victim)
    local real y1=GetUnitY(victim)
   
    local real x2=GetUnitX(attacker)
    local real y2=GetUnitY(attacker)
   
    local real victimFacing=GetUnitFacing(victim)*bj_DEGTORAD
    local real attackAngle=Atan2(y2-y1,x2-x1)
   
    set attackAngle=Acos(Cos(attackAngle-victimFacing))
   
    return (attackAngle*bj_RADTODEG)>120
endfunction

Dunno why it works though, I already forgot.

GUI would be better since I don't know how to implement this with a spell.

An easier way is to get facing angle of unit and then add 180 to it. That new facing will be in the back of the unit.

Mind giving me a trigger?
 

sentrywiz

S

sentrywiz

I can't give you a trigger atm.

You do set realVariable = unit - get facing action.
Then realVariable + 180.
Then set unit facing to realVariable.

I think you misunderstand me. I don't want to backstab a unit, I want a condition to check if a unit is standing behind another unit when he casts the spell.
 
Level 17
Joined
Jan 18, 2010
Messages
1,122
You only really have to check the facing of the units, for a unit to be behind a unit it needs to have the same or similar facing angle, + 180 would be for units that face each other.
Location does not matter, because unless the unit is already behind the target it would have to face it returning false.
 

sentrywiz

S

sentrywiz

You only really have to check the facing of the units, for a unit to be behind a unit it needs to have the same or similar facing angle, + 180 would be for units that face each other.
Location does not matter, because unless the unit is already behind the target it would have to face it returning false.

I know its simple enough, countless maps have it. But its complex enough for me to not be able to trigger it.

So can you give me a trigger with just the condition checking if the casting unit is behind the target of ability unit?
 
Level 17
Joined
Jan 18, 2010
Messages
1,122
Just do an and>real condition like.
  • ((Facing of (Target unit of ability being cast)) Less than or equal to ((Facing of (Casting unit)) + 25.00)) and ((Facing of (Target unit of ability being cast)) Greater than or equal to ((Facing of (Casting unit)) - 25.00))
In GUI that should be enough.
 
Level 15
Joined
Oct 29, 2012
Messages
1,474
Well this needs a little bit knowledge of Angle Maths
A Unit is behind a unit means the angle of the backstabbing unit should be lesser than (Back-stabbed Unit's Angle) - 125 and greater than (Back-stabbed Unit's Angle) + 125
So he definitely stands within angle between 125 and 275 according to the back-stabbed unit's angle. I tried it once so it must work
NOTE: What I mean by 'Target Unit' is (Target Unit of Ability Being Cast)
NOTE 2: Store the more-than-twice used values in variables, you know what I mean.
Here is the condition :
  • Conditions
    • If And/All conditions are true
      • (Facing Angle of (Triggering Unit)) Greater than ( (Facing Angle of (Target Unit)) + 125 )
      • (Facing Angle of (Triggering Unit)) Lesser than ( (Facing Angle of (Target Unit)) + 275)
@Talavaj :
This one detects all nearby units but front ones. In other words, it detects units who are right-side and left-side too. So instead of using 25 use 125 it only detects backside units.
  • ((Facing of (Target unit of ability being cast)) Less than or equal to ((Facing of (Casting unit)) + 25.00)) and ((Facing of (Target unit of ability being cast)) Greater than or equal to ((Facing of (Casting unit)) - 25.00))
 
Comparing the angles might work best. . . Since you already got some answers I shall provide you with another answer. =)

This is an example of using a damage detection for a passive backstab.
[trigger=ex.]
Events
Game - damageEventTrigger becomes Equal to 1.00
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
damageType Equal to PHYSICAL
Then - Actions
-------- Actions for PHYSICAL damage --------
Set backstabunit1 = source
Set backstabunit2 = target
Set p = (Position of backstabunit1)
Set p2 = (Position of backstabunit2)
Set r1 = (Angle from p to p2)
Set r2 = (Facing of backstabunit2)
Set r3 = (Cos((r1 - r2)))
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
r3 Greater than 0.00
Then - Actions
Special Effect - Create a special effect attached to the chest of backstabunit2 using Objects\Spawnmodels\Human\HumanLargeDeathExplode\HumanLargeDeathExplode.mdl
Special Effect - Destroy (Last created special effect)
Else - Actions
Set backstabunit1 = No unit
Set backstabunit2 = No unit
Custom script: call RemoveLocation(udg_p)
Custom script: call RemoveLocation(udg_p2)
Game - Display to (All players) for 10.00 seconds the text: ((Name of source) + ( damages + ((Name of target) + ( with damage: + (|cffff0000 + (String(amount)))))))
-------- End of Actions for PHYISCAL damage --------
Else - Actions
[/trigger]

Yeah it works as well, hope I helped since this according to your first post was using something similar to this. I am somewhat sure chobibo gave you the JASS version of this though his uses 120 as the final detection so I don't know.
 
Level 17
Joined
Jan 18, 2010
Messages
1,122
@jonhysone
I don't think that would work.

Keep in mind that real facing angle +/- value will result in degrees below/above 0~360 which will cause accuracy errors if unit is facing angles around 0/360 deg.
My example is very very crude, it wouldn't work if the units are facing 1 and 360 degrees for example.
 

sentrywiz

S

sentrywiz

Thanks for all of your inputs.

+rep to Talavaj, jonhysone, Dat-C3.

I'll check all of your answers and try them all out. I'll see what works best for me.
 
Level 15
Joined
Oct 29, 2012
Messages
1,474
Well bro I've mistaken something as my mate mentioned above , thus I've attached a sample map to check a valid backstab.

It now works and checks if the backstab is valid. Once you move the unit with a different angle it won't show a valid backstab.
 

Attachments

  • Backstab valid.w3x
    16.5 KB · Views: 39

sentrywiz

S

sentrywiz

Well I needed backstab for a spell, not when an attack happens. But still good to know!
 
Status
Not open for further replies.
Top