Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unity 5.x Cookbook

You're reading from   Unity 5.x Cookbook More than 100 solutions to build amazing 2D and 3D games with Unity

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher Packt
ISBN-13 9781784391362
Length 570 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Table of Contents (14) Chapters Close

Preface 1. Core UI – Messages, Menus, Scores, and Timers 2. Inventory GUIs FREE CHAPTER 3. 2D Animation 4. Creating Maps and Materials 5. Using Cameras 6. Lights and Effects 7. Controlling 3D Animations 8. Positions, Movement and Navigation for Character GameObjects 9. Playing and Manipulating Sounds 10. Working with External Resource Files and Devices 11. Improving Games with Extra Features and Optimization 12. Editor Extensions Index

NPC NavMeshAgent to seek or flee destination while avoiding obstacles


The introduction of Unity's NavMeshAgent has greatly simplified the coding for NPC and enemy agent behaviors. In this recipe, we'll add some wall (scaled cubes) obstacles, and generate a NavMesh, so that Unity knows not to try to walk through the walls. We then add a NavMeshAgent component to our NPC GameObject, and tell it to head to a stated destination location by intelligently planning and following a path, while avoiding the wall obstacles.

In the next screenshot, we can see in the Scene panel the squares that represent potential points on the path. We can also see lines showing the current temporary direction and destination around the current obstacle.

When the Navigation panel is visible, then the Scene panel displays the blue-shaded walkable areas, and unshaded, non-walkable areas at the edge of the terrain and around each of the two wall objects.

Getting ready

This recipe builds upon the player-controlled 3D cube...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image