Giving a little perspective

The perspective sense will detect whether a specific aspect is within its field of view and visible distance. If it sees anything, it will take the specified action, which in this case is to print a message to the console.

The code in the Perspective.cs file looks like this:

using UnityEngine;public class Perspective : Sense{    public int fieldOfView = 45;    public int viewDistance = 100;    private Transform playerTransform;    private Vector3 rayDirection;    protected override void Initialize()     {        playerTransform = GameObject.FindGameObjectWithTag("Player").transform;    }    protected override void UpdateSense()     {        elapsedTime += Time.deltaTime;        if (elapsedTime >= detectionRate)         {            DetectAspect();        }  } //Detect perspective field ...

Get Unity 2017 Game AI Programming - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.