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

[Spell] "Fleeing" system

Status
Not open for further replies.
Level 21
Joined
Mar 29, 2020
Messages
1,237
Hey people,

I am creating AI for a map of mine, and I'm trying to create a function to make a unit flee from units that are chasing it. The problem is that it could be chased by multiple units at the same time, and I'm not sure how I would be able to create a system that would detect which multiple directions the unit is being chased from, and know how to calculate the correct angle to run to, to help get away.
also to be able to sift through the chasers and give them diff levels of priority so that if it is being chased from all sides - it will run towards weaker enemies.

I'm really not sure how to attack this problem... any help would be welcome...

thanks!
 
Level 9
Joined
Mar 26, 2017
Messages
376
I have a flee spell in my map that works well, but involves only running away from one unit.

Perhaps you can make it so that it scans all nearby units, and run in the opposite direction of the unit that is closest by. Or if you would add 'danger' values to chasing units, you could make it a function of distance and a danger multiplier.
 
Level 9
Joined
Mar 26, 2017
Messages
376
If you would go off distance alone, you could enumerate all nearby units and assign a value to them equal to distance. The lowest distance is the most promiment threat, and therefore the fleeing unit shall be ordered to run in the opposite direction of their position.

However, if you find that some units should be considered greater threats than others, you could make some sort of a function. For instance if a abomination is more dangerous than a ghoul, you could always subtract 100 from the distance value. So that a abomination at 250 distance will be considered a more prominent threat than a ghoul at 200 distance, but if the ghoul would be much closer, then the ghoul would be considered more dangerous rather.


My own spell is not intended as an AI, but more as a thematic group disable spell. In detail: every .5 seconds it orders affected units to move to a location 260 units away from their current location in the opposite direction of the spellcaster. Because of the short timing interval it works smoothly, and units naturally move away from the caster, unless they are completely backed into a corner.

But the intention of my spell is mostly to disable enemies, and not so much to optimise their fleeing patterns.
 
Level 21
Joined
Mar 29, 2020
Messages
1,237
this is what I did so far....just a fleeing system to avoid walls while running from one unit. it's kind of ugly... I intend on converting it to jass and optimizing it. The main con is that sometimes when the fleer is between a wall and the chaser - he acts kind of schitzofrenic and runs back and forth. besides that it's kind of ok.

If you would go off distance alone, you could enumerate all nearby units and assign a value to them equal to distance. The lowest distance is the most promiment threat, and therefore the fleeing unit shall be ordered to run in the opposite direction of their position.

However, if you find that some units should be considered greater threats than others, you could make some sort of a function. For instance if a abomination is more dangerous than a ghoul, you could always subtract 100 from the distance value. So that a abomination at 250 distance will be considered a more prominent threat than a ghoul at 200 distance, but if the ghoul would be much closer, then the ghoul would be considered more dangerous rather.


My own spell is not intended as an AI, but more as a thematic group disable spell. In detail: every .5 seconds it orders affected units to move to a location 260 units away from their current location in the opposite direction of the spellcaster. Because of the short timing interval it works smoothly, and units naturally move away from the caster, unless they are completely backed into a corner.

But the intention of my spell is mostly to disable enemies, and not so much to optimise their fleeing patterns.

thanks, maybe I'll use that.

  • run away gui
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet temppoint = (Position of Tauren Chieftain 0002 <gen>)
      • Set VariableSet temppoint2 = (Position of Mountain King 0004 <gen>)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between temppoint and temppoint2) Less than or equal to (Unit: Tauren Chieftain 0002 <gen>'s Real Field: Sight Radius ('usir'))
        • Then - Actions
          • Set VariableSet firstangle = (Angle from temppoint to temppoint2)
          • Set VariableSet otherway = (temppoint offset by -600.00 towards firstangle degrees.)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Playable map area) contains otherway) Equal to True
            • Then - Actions
              • Set VariableSet Destination = otherway
              • Unit - Order Tauren Chieftain 0002 <gen> to Move To Destination
            • Else - Actions
              • Game - Display to (All players) the text: hit the wall
              • Set VariableSet angle = 90.00
              • Set VariableSet RandNum = (Random real number between 0.00 and 2.00)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandNum Greater than or equal to 1.00
                • Then - Actions
                  • -------- Turn Left --------
                  • For each (Integer A) from 1 to 30, do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • enderbool Equal to True
                        • Then - Actions
                          • Set VariableSet leftT = (temppoint offset by -250.00 towards (firstangle + angle) degrees.)
                          • Special Effect - Create a special effect at leftT using Objects\Spawnmodels\NightElf\EntBirthTarget\EntBirthTarget.mdl
                          • Special Effect - Destroy (Last created special effect)
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • ((Playable map area) contains leftT) Equal to True
                            • Then - Actions
                              • Game - Display to (All players) the text: turn left
                              • Set VariableSet Destination = leftT
                              • Set VariableSet enderbool = False
                              • Unit - Order Tauren Chieftain 0002 <gen> to Move To Destination
                            • Else - Actions
                          • Custom script: call RemoveLocation(udg_leftT)
                        • Else - Actions
                          • Set VariableSet angle = (angle + 20.00)
                • Else - Actions
                  • -------- Turn Right --------
                  • For each (Integer A) from 1 to 30, do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • enderbool Equal to True
                        • Then - Actions
                          • Set VariableSet rightT = (temppoint offset by -250.00 towards (firstangle - angle) degrees.)
                          • Special Effect - Create a special effect at rightT using Objects\Spawnmodels\NightElf\EntBirthTarget\EntBirthTarget.mdl
                          • Special Effect - Destroy (Last created special effect)
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • ((Playable map area) contains rightT) Equal to True
                            • Then - Actions
                              • Game - Display to (All players) the text: turn right
                              • Set VariableSet Destination = rightT
                              • Set VariableSet enderbool = False
                              • Unit - Order Tauren Chieftain 0002 <gen> to Move To Destination
                            • Else - Actions
                          • Custom script: call RemoveLocation(udg_rightT)
                        • Else - Actions
                          • Set VariableSet angle = (angle + 20.00)
        • Else - Actions
      • Set VariableSet enderbool = True
      • Custom script: call RemoveLocation(udg_otherway)
      • Custom script: call RemoveLocation(udg_temppoint)
      • Custom script: call RemoveLocation(udg_temppoint2)
      • Custom script: call RemoveLocation(udg_Destination)
 
Last edited:
Level 12
Joined
Nov 3, 2013
Messages
989
You could take all nearby enemy units and average their coordinates, then have the fleer flee with the angle from that position (the average from the surrounding units) to it's own.


For instance, let's say there's 1 unit that's really close in front of it, but there's 3 units behind it. Do you really want to flee back into those 3 units just because 1 unit is closer?



If you combine that with some weighting so more dangerous units have a bigger impact, then it should be pretty good. The only issues are that distance obviously doesn't take pathing in to account.



Well, actually I guess it wouldn't be the average position of the units, since that would make units further away weigh more and closer units weigh less, but I think you get the idea
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
I think Heroes of the Storm did this by using a "heat map". Threats such as AoE skills and heroes apply heat to the map in an area depending on their threat. The AI then tries to position itself in a "cold" area of the map. Tougher or faster units could generate more heat, and if no cold area is available the AI would move to the coolest available area such as towards the weakest chasing unit.

This approach is not perfect. Anyone who plays Heroes of the Storm can easilly see some of the flaws that can happen. Such as AI running into corners, repeatedly walking in and out of AoE abilities and even running around like a headless chicken when some high threat channels are used.
 
Status
Not open for further replies.
Top