itch.io is community of indie game creators and players

Devlogs

Tech Post #3 - Pressure and Avoidance

Last Frontier
A downloadable game

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:

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.

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:

Read comments (4)