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

The seeing function using a graph-based system


We will start the recipes oriented to use graph-based logic in order to simulate sense. Again, we start by developing the sense of vision.

Getting ready

It is important to have grasped the chapter regarding path finding in order to understand the inner workings of the graph-based recipes.

How to do it…

We will just implement a new file:

  1. Create the class for handling vision:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    
    public class VisorGraph : MonoBehaviour
    {
        public int visionReach;
        public GameObject visorObj;
        public Graph visionGraph;
    }
  2. Validate the visor object in case the com:

    void Start()
    {
        if (visorObj == null)
            visorObj = gameObject;
    }
  3. Define and start building the function for detecting the visibility of a given set of nodes:

    public bool IsVisible(int[] visibilityNodes)
    {
        int vision = visionReach;
        int src = visionGraph.GetNearestVertex(visorObj);
        HashSet<int> visibleNodes...
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