Reader small image

You're reading from  Unity 5.x Game AI Programming Cookbook

Product typeBook
Published inMar 2016
PublisherPackt
ISBN-139781783553570
Edition1st Edition
Tools
Right arrow
Author (1)
Jorge Palacios
Jorge Palacios
author image
Jorge Palacios

Jorge Palacios is a software and game developer with a BS in computer science and eight years of professional experience. He's been developing games for the last five years in different roles, from tool developer to lead programmer. Mainly focused on artificial intelligence and gameplay programming, he is currently working with Unity and HTML5. He's also a game-programming instructor, speaker, and game-jam organizer.
Read more about Jorge Palacios

Right arrow

Creating good waypoints


There are times when the number of waypoints must be reduced at a certain point during the game or just for memory constraints. In this recipe, we will learn a technique called condensation that helps us deal with this problem, forcing the waypoints to compete with each other given their assigned value.

Getting ready

In this recipe, we will deal with static member functions. It is important that we understand the use and value of static functions.

How to do it…

We will create the Waypoint class and add the functions for condensing the set of waypoints.

  1. Create the Waypoint class, deriving not only from MonoBehaviour, but also from the IComparer interface:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    
    public class Waypoint : MonoBehaviour, IComparer
    {
        public float value;
        public List<Waypoint> neighbours;
    }
  2. Implement the Compare function from the aforementioned interface:

    public int Compare(object a, object b)
    {
        Waypoint wa...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Unity 5.x Game AI Programming Cookbook
Published in: Mar 2016Publisher: PacktISBN-13: 9781783553570

Author (1)

author image
Jorge Palacios

Jorge Palacios is a software and game developer with a BS in computer science and eight years of professional experience. He's been developing games for the last five years in different roles, from tool developer to lead programmer. Mainly focused on artificial intelligence and gameplay programming, he is currently working with Unity and HTML5. He's also a game-programming instructor, speaker, and game-jam organizer.
Read more about Jorge Palacios