Book Image

Unity 5.x By Example

By : Alan Thorn
Book Image

Unity 5.x By Example

By: Alan Thorn

Overview of this book

Unity is an exciting and popular engine in the game industry. Throughout this book, you’ll learn how to use Unity by making four fun game projects, from shooters and platformers to exploration and adventure games. Unity 5 By Example is an easy-to-follow guide for quickly learning how to use Unity in practical context, step by step, by making real-world game projects. Even if you have no previous experience of Unity, this book will help you understand the toolset in depth. You'll learn how to create a time-critical collection game, a twin-stick space shooter, a platformer, and an action-fest game with intelligent enemies. In clear and accessible prose, this book will present you with step-by-step tutorials for making four interesting games in Unity 5 and explain all the fundamental concepts along the way. Starting from the ground up and moving toward an intermediate level, this book will help you establish a strong foundation in making games with Unity 5.
Table of Contents (15 chapters)
Unity 5.x By Example
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Enemy AI – range of sight


Let's now start developing enemy AI by thinking about our functional requirements. The enemies in the scene will begin in patrol mode, wandering the level from place to place searching for the player character. If the player is spotted, the enemy will change from patrolling and begin chasing the player, attempting to move closer to them for an attack. If the enemy reaches within attacking range of the player, the enemy will change from chasing to attacking. If the player outruns the enemy and successfully loses them, the enemy should stop chasing and return to patrolling again, searching for the player as they were doing initially. This, in sum, describes our needed enemy AI behavior.

To achieve this behavior, we'll need to code the line of sight functionality for the enemy. The enemy relies on being able to see the player character or determining whether the player is visible to the enemy at any one moment. This helps the enemy decide whether they should patrol...