Adding AI States

Adding new AI States is similar to adding states for the player. Therefore, this guide will only highlight the differences between player states and AI states.

  • The primary distinction lies in the creation of a new state asset. For AI States, select Create -> C# UHFPS Templates -> AIState Script to generate a new AI State script.

  • The AI state implements the FSMAIState class, which includes various methods and references.

  • From the AIState, you can access essential player components, like the player state machine, player health or player manager.

It is recommended to examine the existing states and methods in FSMAIState to get an overview of how the different functionalities are implemented and what you can use in your states. Each method is commented so you will know how and which method you can use.

Adding Waypoints

  1. Create a new empty game object and name it Waypoints or whatever you want.

  2. Add the AI Waypoints Group component to the game object.

  3. Create a new empty game object and add it to the parent of the Waypoints object.

  4. Add the AI Waypoint component to the parent object. When you add new objects with the AI Waypoint component to the parent of the Waypoints object, the AI Waypoint Group will automatically handle the waypoint list, so you don't need to manually add or remove them.

There's no need to assign the waypoints to the NPC State Machine. To utilize the waypoints, simply call the FindClosestWaypointsGroup() method from the FSMAIState class to locate the nearest waypoints based on the NPC's position. You can call this method when you enter a state or whenever you want.

To obtain an unreserved waypoint from the AI Waypoints Group, just use the GetFreeWaypoints() method from FSMAIState. It's a good to reserve the waypoint once you've acquired it, so that when multiple NPCs are present, they won't head towards the already reserved waypoints.

To reserve a waypoint, assign the NPC object to the ReservedBy object within the AI Waypoint component. To unreserve it, simply change that reference to null.

Last updated