Repositioning Enemies - Explained


Normally the best way to be able to beat an enemy in any game is to understand exactly how they work. One of the more complicated features for the enemies in Tenril is their ability to reposition themselves for an attack. The better you can understand this, the better you will be able to predict the action they might be taking.

The main reason for this feature was due to some limitations with the game engines' built-in way for character navigation, as it works perfectly for making our enemy move towards a point, but does not work when moving away from a point. This is where this repositioning movement mechanic comes into place.

To briefly explain it in practice, when an attack is not possible due to being too close or too far away from a target, the enemy will try to choose a direction to move towards to be within range for the current attack, or until it runs out of time and chooses a new attack to try and perform.

This repositioning mechanic had gone through many iterations, most of which had failed due to the enemy struggling to move around obstacles, or due to them getting stuck when two paths are nearly equally liked.

Repositioning Prototype

- Prototype where the AI would get stuck trying to use two desirable directions simultaneously.

However, after a lot of prototyping, this was refined and drastically improved. This movement works by using something known as a ray cast, which is a beam that goes in any given direction and can be used to check for potential obstacles around the enemy. These beams are fired out from the enemy in all directions around it so that it could have a clear understanding of its surroundings.

These rays can also keep track of additional information, such as how valuable or important it is. The value of these directions is decided on by comparing several factors. The most common one is how desirable an obstacle is, often making a direction less valuable as to avoid bumping into them. The next most important factor is to compare how close this direction is to the enemy target, which will vary depending on if we want to move away or towards it. Once the value of every direction is calculated, they are combined based on how valuable they are, and with some minor tweaks to balance and smooth out the calculation, the AI is now able to move towards or away from a target with a lower risk of bumping into obstacles and getting stuck.

Repositioning Away

- Visualized rays of different colors to reflect how desirable one direction is over another.

Although the current implementation of this repositioning movement works quite well, it still has its flaws and will likely be updated in the future to be smoother and better at obstacle detection. But with this, I hope you've all learned a bit on how their ability to reposition works, have perhaps already thought of ways how to take advantage of it in your fights, and enjoy the game further!

Get Tenril

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.