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:
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; }
Validate the visor object in case the com:
void Start() { if (visorObj == null) visorObj = gameObject; }
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...