Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unity AI Programming Essentials

You're reading from   Unity AI Programming Essentials Use Unity3D, a popular game development ecosystem, to add realistic AI to your games quickly and effortlessly

Arrow left icon
Product type Paperback
Published in Dec 2014
Publisher
ISBN-13 9781783553556
Length 162 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Curtis Bennett Curtis Bennett
Author Profile Icon Curtis Bennett
Curtis Bennett
Arrow right icon
View More author details
Toc

Creating cover AI


Our AI enemy will just keep attacking the player as long as it is close enough to the ship. However, this isn't very realistic; we'd like the enemy ship to attack for a little bit but then duck and head for cover. We could have this hiding behavior be based on a response to the player fighting back, but for this demo, we will make it a constant value of 5 seconds; after attacking the player for 5 seconds, it will hide.

To set this up, first we'll add an isHidingbool variable to our behavior tree that is set to true after 5 seconds of attacking. Create a new constraint node under the root parallel node with the playerAttack != null && isHiding == false expression. This node's children start when playerAttack is valid and we are not already hiding from the player. Add a sequencer node under this constraint so it will go through all of its children. The first child needs to be a new timer node with the Seconds value of 5 and Returns set to Success. Next, copy the don...

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