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

[General] Detect that unit is running away from the enemies

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,503
If the enemy heroes are always near each other then I suppose you could do something like this.

Choose one of these enemy heroes as the "leader" and periodically compare 2 things to your unit:
1: The angle between the leader and the unit to determine that the unit is facing away.
2: The unit's distance from the leader to determine that the unit is moving away and not closer.

#2 could be handled like this:
set variable Distance = distance between position of leader and position of unit
if (Distance < previousDistance) then set variable IsMovingAway = True
set variable previousDistance = Distance

Then you could add onto the If Then Else statement like:
if (#1 is true and Distance < previousDistance) then set variable IsMovingAway = True

I forget the math for the "facing away" stuff but there's probably an example of this idea in here: [Solved] - Angles (how to detect a backstab attack)?
 
Level 7
Joined
Feb 9, 2021
Messages
301
If the enemy heroes are always near each other then I suppose you could do something like this.

Choose one of these enemy heroes as the "leader" and periodically compare 2 things to your unit:
1: The angle between the leader and the unit to determine that the unit is facing away.
2: The unit's distance from the leader to determine that the unit is moving away and not closer.

#2 could be handled like this:
set variable Distance = distance between position of leader and position of unit
if (Distance < previousDistance) then set variable IsMovingAway = True
set variable previousDistance = Distance

Then you could add onto the If Then Else statement like:
if (#1 is true and Distance < previousDistance) then set variable IsMovingAway = True

I forget the math for the "facing away" stuff but there's probably an example of this idea in here: [Solved] - Angles (how to detect a backstab attack)?
I thought about this approach, but there are a couple of problems with it. I am creating a MOBA map, so choosing the enemy "leader" is very problematic. Sometimes it is better to focus range carry, and sometimes it is better to focus melee. In terms of the approach, if an enemy hero chases the unit, then it will not work since the distance will be around the same.

So, there is a need for something that considers all units around the hero.
 
Level 4
Joined
Feb 16, 2017
Messages
54
What is a good way to detect that the unit is running away from the enemy heroes?
I have an idea;

Now get a trigger that runs every 0.02 seconds.
Suppose we have two time variables.
The first is 0.20(timer) and the second is the counter(timecount).
And if we have one real variable (xreal), this tells us how far a unit can escape in 0.20 (timer) seconds, let's be meters.
We will initially assign a variable for the distance between the fleeing unit and the attacking unit.(yRealFirst)
The counter will check this variable again after 0.20 seconds and reassign the distance to a new variable (yRealEnd),
if after 0.20 seconds(timecount==timer) ,distance between fleeing unit and attacking unit(yRealEnd) - distance between first fleeing unit and attacking unit(yRealFirst) > (xreal) , fleeing unit is fleeing attacking unit ='true'
 
Level 4
Joined
Feb 16, 2017
Messages
54
The logic of this is;

first we set a time, we calculate how many meters the slowest unit can travel in that time (the reason we do this is that this trigger works correctly on the slowest unit, and if a unit is running it will walk without stopping, so we will calculate the total meters walked for the time we set without stopping)


Then we will decide if he has escaped by watching the distance changes between the attacker and the fleeing unit.

If a unit is running away, it will keep walking, so the walking distance in the time we set will work.

however , if a unit is not running , sometimes it stays in place , so the distance variation is not much.

sorry i use translation i hope you understand me
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,503
Alternate idea: When you issue a Move order towards a point, calculate the distance between that and each enemy hero. If it's not near any of them (distance <= 800) then you can mark the unit as "retreating".

Only issue is this requires manual orders so a unit that's naturally fleeing without being ordered to do so will ignore the trigger.

Anyway, it's very difficult to figure this out since there's nothing stopping a player from being sandwiched between multiple heroes. They could be fleeing from one while running towards another.
 
Level 4
Joined
Feb 16, 2017
Messages
54
Alternate idea: When you issue a Move order towards a point, calculate the distance between that and each enemy hero. If it's not near any of them (distance <= 800) then you can mark the unit as "retreating".

Only issue is this requires manual orders so a unit that's naturally fleeing without being ordered to do so will ignore the trigger.

Anyway, it's very difficult to figure this out since there's nothing stopping a player from being sandwiched between multiple heroes. They could be fleeing from one while running towards another.
How do you think my opinion
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,188
Running away can generally be defined as a unit's movement vector being away from the unit it is running from. This could be calculated periodically and tested. If it passes too many "run away" tests then it can be considered as running away.

Unit facing alone cannot be used to determine if a unit is running away since it has no direct relationship with trying to gain significant distance from a unit. A unit could be turning its back to another unit to cast an ability such as a heal, while standing and face tanking enemies behind it.

Instantaneous movement deltas alone cannot be used to determine if a unit is running away since tactical repositioning is part of micro gameplay during combat and has no direct relationship with trying to gain significant distance from a unit. For example a player might split their archer group in response to a Blizzard channel to avoid them taking damage from the hazard area, during which time they might move in all directions, including away from the unit, only to immediately turn around and start attacking when outside the hazard.

This is why a general trend of movement away from the unit has to be used to determine if a unit is running from another. If the unit is occupied for a significant amount of time with movement and has travelled a significant distance in a direction away from a unit, then there is a good chance it is trying to run away, and not just repositioning or turning to target something behind.
 
Level 7
Joined
Feb 9, 2021
Messages
301
Thanks, everyone for contributing. I will try to build something based on Dr Super Good's suggestion. I am thinking about using the Motion System for direction.
 
Status
Not open for further replies.
Top