We will implement three different classes for handling low-level and high-level AIs, as follows:
- Create the class for the basic rival agent, as shown in the following code:
using UnityEngine; public class RacingRival : MonoBehaviour { public float distanceThreshold; public float maxSpeed; public Vector3 randomPos; protected Vector3 targetPosition; protected float currentSpeed; protected RacingCenter ghost; }
- Implement the Start function, as follows:
void Start() { ghost = FindObjectOfType<RacingCenter>(); }
- Define the Update function for handling the target position to follow, as shown in the following code:
public virtual void Update() { targetPosition = transform.position + randomPos; AdjustSpeed(targetPosition); ...