Our AI character will be roaming around the scene in a random direction. It'll have two senses:
The perspective sense will check whether the enemy aspect is within a set visible range and distance
Touch sense will detect if the enemy aspect has collided with the box collider, soon to be surrounding our AI character
As we have seen previously, our player tank will have the Enemy
aspect. So, these senses will be triggered when they detect the player tank.
The code in the
Wander.cs
file can be shown as follows:
using UnityEngine; using System.Collections; public class Wander : MonoBehaviour { private Vector3 tarPos; private float movementSpeed = 5.0f; private float rotSpeed = 2.0f; private float minX, maxX, minZ, maxZ; // Use this for initialization void Start () { minX = -45.0f; maxX = 45.0f; minZ = -45.0f; maxZ = 45.0f; //Get Wander Position GetNextPosition(); } // Update is called once per frame void Update () { ...