Tech Post #3 - Pressure and Avoidance


Movement in a game can seem trivial, but there's a lot to it.  While Unreal Engine has some convenient AI tools and built in pathfinding, there is still difficulty in figuring out where to go and how to get there.  For this project, much of the area is open with relatively minimal objects.  If you consider a forest (or nearly ANY natural scenery) most pathfinding is fairly trivial and more a factor of elevations.  How hard is it to find a path from A to B if there is just one tree in the way?  This makes the needs of this project very different from, say, a tower defense game where enemies must traverse a literal maze.  Unreal Engine's pathfinding is very ideal for maze traversal, as you can just tell the Actor to go to the end of the maze and the AI system settles it for you.  But what about creature interactions?

Consider the following example:  creature A wants to run away from creature B.  This is fairly straightforward, you can select a location directly opposite of creature A from B and just tell it to "MoveTo".  But what if there are other creatures in the way?  Unreal Engine can identify a path around those creatures (if you set it up right), but it still is more or less heading towards them.

This is where a pressure system can come into play.  We can have all creatures exert a "pressure" on their surroundings based on their perceived threat.  High threat creatures would naturally have more pressure than low threat creatures.  Now, rather than arbitrarily saying "move away from creature B", we can instead have creature A react to creature B's natural pressure to retreat.  This system is especially ideal with our STM (short term memory), as we can have our creature react to all creatures it is currently aware of.  Here is an example illustration:


In all cells, you can think of red as movement direction, blue as pressure, and green as sight range.  The left side shows how our situation works without pressure, and the right shows it with pressure.  In the first example, there is no significant change.  Both creatures run away from the target.  In the second example, our creature would run straight into another one without pressure.  In the third example, our creature is so busy running from the big threat that it collides with many smaller threats.  And in the last example, our creature may end up running back and forth between these creatures as it sees one and forgets the other.  For all of these examples, our pressure system combined with our STM can enable a creature to find an escape path that has the least risk (based on perceived threat).

Now some of the default behavior may sound fun to exploit, but fear not!  Our STM still supports "dumb" creatures with tunnel vision!  If a creature is "dumb" enough that it can only remember 1 or 2 other creatures at a time, then it can be easily exploited!  In other words, our creature's movement decisions can become more sophisticated based on their Reasoning and Intuition attributes! (NOTE:  In previous posts I called this Knowledge.  I forgot that I had chosen to rename Knowledge to Reasoning since it better reflects the core concepts).

Let's take a look at this behavior in action:

In this example (and future ones), you can see the angle of pressure drawn as blue, the movement from pressure as red, and the original path as black.  In this particular example, you can see the two points where it made it's decision to move.  Rather than take the path that leads sharply from the left enemy (the larger/more dangerous one) it skews somewhat to also avoid the two smaller/weaker ones on the right.  Here it is in action:

When combined with the perception system, this means that as our creature sees new enemies it can adjust it's path appropriately, as in this example:

You can see it initially head towards the enemy on the right.  However, once it detects that enemy, it veers away to keep a safer distance.  This behavior works with groups as well of course:

In this instance, it would have run directly into this group of much smaller enemies.  With the pressure system, it instead avoided them.

With that system implemented, we must also correct for another bad behavior.  How would our creature behave if it ran into a wall (or other large, impassable obstacle)?  If it happens to select a viable location beyond the object, and there happens to be a path to it, then the Unreal Engine pathing system kicks in and can correct for it.  But that's a lot of ifs!  With our pressure-based system, there is still the concern of a threat's pressure "pushing" the creature into the wall and forcing it to be stuck.  So, we can have our creature identify when its path is blocked (using raycasting) and attempt to find another direction to move.  Consider the following illustration:

In the upper example, our creature has been "pressured" into a wall and is now stuck.  But by identifying that the path is blocked and searching for alternative angles of movement, we can instead have it glide along the wall.  This decision to alter course along the wall can be seen highlighted in green. Now let's look at that movement in action:

Our creature can now not only navigate along walls, but can identify corners and even turn around (should it come across a dead end).  With this in mind there IS still a chance that there is no viable path due to it being surrounded or otherwise stuck.  While this may seem like a bad thing, it will be part of our mechanics later!  (Be cautious cornering a scared animal...)

And with that, our basic navigation has improved a lot!  I want to take time to tinker with Unreal's pathing system to create one that utilizes our pressure concept, enabling us to utilize it even when approaching our targets like so:

However, that is a task for another time!  Now that we have some basic approach and retreat movement going on, we can take our next step towards a basic simulation of wildlife:  combat!  Keep in mind that as our first baby step, this probably won't LOOK all that cool, but it will help establish basic mechanics and enable us to start testing some basic evolution!  Until next time!

Comments

Log in with itch.io to leave a comment.

A couple thoughts around this system and potential other correlating systems that might end up operating together as a sort of "Fight or Flight" engine...

  1. "Fight-to-flee" behaviors, that seek to tactically inhibit a foe's ability to pursue.
    1. Immediate sense is that there's some context of "observed original pursuit potential" versus "observed inhibited pursuit potential"
  2. "Pounce" solo behaviors, supporting a short-term burst of either straight-line (cheetah) behavior or aoe/agility (jackrabbit or snake) that may go unobserved in the pressure
    1. E.g. "I see how fast that thing's moving and account for that speed but get surprised when I move in such a way that causes the pursuer/pursued to engage their burst"
  3. "Herd" vs "HerdING" social behaviors, seeking to manipulate pressure complexity through grouping with like-entities
    1. Same-species
    2. Symbiotic-species?
  4. "Cornering" the animal, either through physical or perceived barriers, resulting in a "fight-to-the-death" versus "fight-to-flee"
    1. (as you'd hinted at earlier, with the "fight-to-flee" idea)
  5. "Beguiling" behaviors, where a would-be pursuer/pursued attempts to subvert another creature's "programming" by behaving in a way counter to expectations
    1. Rushing a predator trying to close distance
      1. Bear rush, or a rabbit running at the predator just to zip around them & take advantage of a perceived low-agility
    2. Posing as weak in order to gain some form of advantage
    3. Lure into disfavorable terrain, "playing dead/damaged", a social ambush, or into an optimal range

Right.  It's a small step for now, but helps establish some basic mechanisms that can be used for intelligent behaviors later. 

A big concept this works towards is  perceived threat vs. actual threat.  By enabling individuals to move/act based on how much danger they "think" they're in, we can enable players (and creatures) the opportunity to "trick" them.  This makes them intelligent enough to be exploited, and ideally that'll be reflected in their evolution patterns as well. 

Also, by giving creatures a sort of survival instinct I hope to make encounters much more interesting.  Evolution and behaviors will trend towards survival when the environment becomes dangerous to them. 

(2 edits)

You know... That same datapoint could feed into a sort of long-term "Migration" system too, where creature species in a localized region have some form of tolerance threshold ceiling and/or rate-over-time for threat, where surpassing it results in the dramatic decision for them to attempt to migrate regions. 

Could ultimately work well for them or for the new regions' species, or terribly, or some combination.  Plus it might deprive the OLD region from an important food source or otherwise destabilize it, resulting in a natural cascade migration/extinction/regrowth effect. The idea of an Apex predator feeling so threatened they shift regions only to THEN completely destabilize the region they shifted towards... that sounds like a delightful interaction.

Such a system might indirectly result in Species that feel threatened by humans ending up naturally moving away if human population centers get closer (b/c it would be causing an increase in traffic e.g. "threat" application).

And probably would need to apply a statistic approach to account for outlier scenarios, like where humans decide to just bully the same one/two individual creatures but the rest of the species in the region is left alone?  Plus some kind of "transition period buff" to give the environment time to at least try to stabilize after a migraine event occurs.