With control of the player character's location and rotation achieved it's time to work on something else that will grab the players attention and challenge them, the enemy AI.
I have had some poor experience with programming AI during my Trash Collector project so in this project I am going to attempt multiple different ways of programming enemies then choose one that bets fits my use case afterwards.
1st Enemy - Simple AI
The quickest and easiest solution is to do the same as when moving the player character and simply grab the enemies current location then linearly move between that and a desired new location, luckily for me this is a pre-programmed function of Unreal Engine in the "AI MoveTo" node which will linearly transition between the starting location of any Pawn class plugged into the node and then the location data plugged into the "Destination" pin. I started by selecting the player characters location as the destination so even if the player was not currently standing at Target Point #2's location this "Simple AI" enemy will still chase the player.
2nd Enemy - Spline path
Another method is to use a spline to determine the path that an enemy would take. This is a much better fit for my use case as this method is adjustable, the spline can be extended and moved around the level multiple times and the enemy will still follow its trail. To do this however the enemy character blueprint needs to know which of many splines contained within this level it should be following so for that I created a instance editable variable that the developer working on the level can use to attach all the different instances of enemies there are in the level to the appropriate splines. For actually moving the enemy actor along the path of the spline I will set the location of the enemy at the location found at the "Distance" along the spline but the selected distance input will be a float that changes over time, this changing float is going to vary depending on the current point that the timeline is at. The distance is going to go between 0 and the max length of the spline using the timeline out float as an alpha which is how this variable is changing over time.
3rd Enemy - Behaviour Tree
Whenever I attempt to search up programming an enemy character the results I get back are always referring to a behaviour tree (or a behaviour tree like structure) which is a class of code that can take note of a series of tasks and then use an algorithm to decide between the outcomes and make a choice of what actions to perform based upon some parameters attached to those tasks. Inside Unreal Engine a Behaviour Tree is accompanied by a Blackboard which is where the series of possible tasks and information a Behaviour Tree needs is stored within the project. This is how most typical 3D games program their enemies as it allows for the AI to not only choose between chasing the player or patrolling a nav mesh, it also allows for the AI to back away from the player character if the player character is marked as being in a rage state or allow for the AI to decide it's shield is too low to continue on the offensive against the player.
While a behaviour tree algorithm is incredibly useful I do not feel it is required for this project or will add enough additional value to the player experience over choosing to use the 2nd Enemy method of attaching the actors to pre-planned spline paths.
Comments
Post a Comment