Skip to content

How to use the AI

James McGowan edited this page Jun 10, 2020 · 1 revision

When creating the AI you will need to make sure that it has a GameObject with a transform and that you add the AI controller script to the AI.

You will also have to change the animations that are in the animation folder. To do that open up the animation delete the current one and add the new one.

Idle

  • This is the starting state. Once a set amount of time has passed the AI will chnage state.
  • In the editor you will have to set the Start Wait Time for how long you want the player to wait.

Patrol

  • Once the time has passed in the Idle state it changes to the patrol state.

  • This state will allow the AI to patrol around a set area within the game, this is done by setting the minX, minY and the maxX, maxY.

  • This is where the GameObject is used. This will be set a random position within the set area above and the point will move around once the AI has reached the previous destination. When the AI reaches its destination it will go to the idle state.

  • Within the patrol state there is a RaycastHit that will detect when the AI hits a object under the layer Building, you can add more layers and add it to the mask. If the AI hits an object it will set the move spot to a new position.

Follow

  • For the follow state, this will use the players postion. When the bool in the animator "isFollow" becomes true the AI will follow the player. The AI can never push the player is this state as there is a distance set so the AI will keep some distance.

  • For this make sure you "isPatrol" false so AI dosen't try to do both.

Clone this wiki locally