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; Â Â Â ...