Skip to Main Content
Building an RPG with Unity 2018 - Second Edition
book

Building an RPG with Unity 2018 - Second Edition

by Vahé Karamian
July 2018
Intermediate to advanced content levelIntermediate to advanced
366 pages
7h 48m
English
Packt Publishing
Content preview from Building an RPG with Unity 2018 - Second Edition

NPC AI

Now it is time to give some intelligence to our NPCs. One of the scripts we will need to create is to give the NPC the ability to detect the player. This script will be called NPC_BarbarianMovement.cs. The script will be used to detect if the player is in-sight, calculate the field of view for the NPC, and calculate the path from the NPC to the player character.

Here is a listing of the source code:

using UnityEngine;using UnityEngine.AI;namespace com.noorcon.rpg2e{public class NPC_BarbarianMovement : MonoBehaviour{// reference to the animatorpublic Animator animator;// these variables are used for the speed// horizontal and vertical movement of the NPCpublic float speed = 0.0f;public float h = 0.0f;public float v = 0.0f;public bool ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Unity 2020 Game Development

Hands-On Unity 2020 Game Development

Nicolas Alejandro Borromeo
Unity 2018 Cookbook - Third Edition

Unity 2018 Cookbook - Third Edition

Matt Smith, Chico Queiroz, Jate Wittayabundit

Publisher Resources

ISBN: 9781788623469Supplemental Content