Creating waypoints automatically
Most of the time, waypoints are assigned manually by the game designer, but what happens if the level has been generated procedurally? We need to come up with an automated solution for our agents.
In this recipe, we will learn a technique called condensation that helps us deal with this problem, allowing the waypoints to compete with each other given their assigned values, meaning the relevant ones will prevail.
Getting ready
We will deal with static member functions. It is important that we know the use and value of static functions.
How to do it...
We will create the Waypoint
class and add the methods for condensing the set of waypoints:
- Create the
Waypoint
class, deriving from bothMonoBehaviour
and from theIComparer
interface:
using UnityEngine; using System.Collections; using System.Collections.Generic; public class Waypoint : MonoBehaviour, IComparer { public float value; public List<Waypoint> neighbours; }
- Implement the
Compare
function from...