AI characters
In this example, the AI characters roam around the scene in a random direction. They have two senses: sight and touch. The sight sense checks whether the enemy aspect is within a set visible range and distance. Touch detects whether the enemy aspect has collided with the Box Collider
around the character. As we have seen previously, our player's tank has the Player
aspect. Consequently, these senses are triggered when they detect the player's tank.
For now, let's look at the script we use to move the NPCs around:
using UnityEngine; using System.Collections; public class Wander : MonoBehaviour { private Vector3 tarPos; [SerializeField] private float movementSpeed = 5.0f; [SerializeField] private float rotSpeed = 2.0f; [SerializeField] private float minX = -45.0f; ...