logo资料库

Unity AI Game Programming - Second Edition.pdf

第1页 / 共232页
第2页 / 共232页
第3页 / 共232页
第4页 / 共232页
第5页 / 共232页
第6页 / 共232页
第7页 / 共232页
第8页 / 共232页
资料共232页,剩余部分请下载后查看
Cover
Copyright
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Table of Contents
Preface
Chapter 1: The Basics of AI in Games
Creating the illusion of life
Leveling up your game with AI
Using AI in Unity
Defining the agent
Finite State Machines
Seeing the world through our agent's eyes
Path following and steering
Using A* Pathfinding
Using navigation mesh
Flocking and crowd dynamics
Behavior trees
Thinking with fuzzy logic
Summary
Chapter 2: Finite State Machines and You
Finding uses for FSMs
Creating state machine behaviors
Creating the AnimationController asset
Layers and Parameters
The animation controller inspector
Bringing behaviors into the picture
Creating our very first state
Transitioning between states
Setting up our player tank
Creating the enemy tank
Choosing transitions
Making the cogs turn
Setting conditions
Driving parameters via code
Making our enemy tank move
Testing
Summary
Chapter 3: Implementing Sensors
Basic sensory systems
Cone of sight
Hearing, feeling, and smelling using spheres
Expanding AI through omniscience
Getting creative with sensing
Setting up the scene
Setting up the player tank and aspect
Implementing the player tank
Implementing the Aspect class
Creating an AI character
Using the Sense class
Giving a little perspective
Touching is believing
Testing the results
Summary
Chapter 4: Finding Your Way
Following a path
The path script
Using the path follower
Avoiding obstacles
Adding a custom layer
Implementing the avoidance logic
A* Pathfinding
Revisiting the A* algorithm
Implementation
Implementing the Node class
Establishing the priority queue
Setting up our grid manager
Diving into our A* implementation
Implementing a Test Code class
Setting up our sample scene
Testing all the components
Navigation mesh
Setting up the map
Navigation Static
Baking the navigation mesh
Using the NavMesh agent
Setting a destination
The Target class
Testing slopes
Exploring areas
Making sense of Off Mesh Links
Using the generated Off Mesh Links
Setting the manual Off Mesh Links
Summary
Chapter 5: Flocks and Crowds
Learning the origins of flocks
Understanding the concepts behind flocks and crowds
Flocking using Unity's samples
Mimicking individual behavior
Creating the controller
Using an alternative implementation
Implementing the FlockController
Using crowds
Implementing a simple crowd simulation
Using the CrowdAgent component
Adding some fun obstacles
Summary
Chapter 6: Behavior Trees
Learning the basics of behavior trees
Understanding different node types
Defining composite nodes
Understanding decorator nodes
Describing the leaf node
Evaluating the existing solutions
Implementing a basic behavior tree framework
Implementing a base Node class
Extending nodes to selectors
Moving on to sequences
Implementing a decorator as an inverter
Creating a generic action node
Testing our framework
Planning ahead
Examining our scene setup
Exploring the MathTree code
Executing the test
Summary
Chapter 7: Using Fuzzy Logic to Make Your AI Seem Alive
Defining fuzzy logic
Picking fuzzy systems over binary systems
Using fuzzy logic
Implementing a simple fuzzy logic system
Expanding the sets
Defuzzifying the data
Using the resulting crisp data
Using a simpler approach
Finding other uses for fuzzy logic
Merging with other concepts
Creating a truly unique experience
Summary
Chapter 8: How It All Comes Together
Setting up the rules
Creating the towers
Making the towers shoot
Setting up the tank
Setting up the environment
Testing the example
Summary
Index
[ 1 ]
Unity AI Game Programming Second Edition Leverage the power of Unity 5 to create stunningly life-like AI entities in your games! Ray Barrera Aung Sithu Kyaw Clifford Peters Thet Naing Swe BIRMINGHAM - MUMBAI
Unity AI Game Programming Second Edition Copyright © 2015 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: July 2013 Second edition: September 2015 Production reference: 1180915 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78528-827-2 www.packtpub.com
Credits Copy Editor Swati Priya Project Coordinator Milton Dsouza Proofreader Safis Editing Indexer Monica Ajmera Mehta Production Coordinator Arvindkumar Gupta Cover Work Arvindkumar Gupta Authors Ray Barrera Aung Sithu Kyaw Clifford Peters Thet Naing Swe Reviewers Mohammedun Bakir Bagasrawala Adam Boyce Jack Donovan Chaima Jemmali Akshay Sunil Masare Commissioning Editor Kartikey Pandey Acquisition Editors Manish Nainani Llewellyn Rozario Content Development Editor Rashmi Suvarna Technical Editors Manal Pednekar Ankita Thakur
About the Authors Ray Barrera was a tinker in his childhood. From making mods and custom maps in games such as StarCraft and Unreal Tournament to developing open source role-playing games using RPG Maker, he always had a passion for game development. The passion stayed with him, and after many years as a hobbyist, he decided to take the plunge into professional development. In the initial stages of his career, he was fortunate enough to work on educational and research projects for major contractors in the defense industry, allowing him to blend his love for games with his innate desire to teach and create interactive experiences. Since then, he has straddled the line between entertainment and education. Unity was the logical weapon of choice for him as it gave him the flexibility to create games and applications and iterate quickly. From being an original member of the Los Angeles Unity meetup to helping coordinate Unity workshops at local colleges and high schools, he has been very active in the Unity community. You can follow him on Twitter at @ray_barrera. There are too many people to name, but I'd like to thank the team at Packt Publishing for this exciting opportunity, and of course, my wonderful friends and family, especially my parents, who always encouraged me to follow my passion and supported me along every step of the way. I'd also like to thank the Twistory team for being such an amazing group of people—Danny, JP, DW, Richard, the lovely "Purple", and everyone else—whom I was so fortunate to work with. Thanks to Peter Trennum for the mentorship and leadership he has provided at this stage in my career. Lastly, I'd like to thank Gianni, my brother, for all the love and support over the years.
Aung Sithu Kyaw has been in the technical industry for over a decade. He is passionate about graphics programming, creating video games, writing, and sharing knowledge with others. He holds an MSc in digital media technology from the Nanyang Technological University (NTU), Singapore. Over the last few years, he has worked in various positions, including research programmer and senior game programmer. Lastly, he worked as a research associate, which involved implementing a sensor-based real-time movie system using Unreal Development Kit. In 2011, he founded a tech start-up, which focuses on interactive media productions and backend server-side technologies. He is currently based in Myanmar and working on his latest company's product, a gamified social opinion network for Myanmar. He can be followed on Twitter at @aungsithu and LinkedIn at http://linkedin. com/in/aungsithu. Thanks to my coauthors who worked really hard with me on this book despite their busy schedules and helped get this book published. Thanks also goes to the team at Packt Publishing for having us produce this book. And finally, thanks to the awesome guys at Unity3D for building this amazing toolset and making it affordable to indie game developers. Dedicated to L! Clifford Peters is a programmer and a computer scientist. He was the technical reviewer for Unity Game Development Essentials, Unity 3D Game Development by Example Beginner's Guide, Unity 3 Game Development HOTSHOT, Unity 3.x Game Development by Example Beginner's Guide, Unity iOS Game Development Beginner's Guide, and Unity iOS Essentials, all by Packt Publishing.
Thet Naing Swe is the founder and CTO of Joy Dash Pte Ltd, based in Singapore. He graduated from the University of Central Lancashire with a major in game design and development and started his career as a game programmer at one of the UK-based Nintendo DS game development studios. In 2010, he relocated to Singapore and worked as a graphics programmer at the Nanyang Technological University (NTU) on a cinematic research project. At Joy Dash, he's responsible for interactive digital media consulting projects, especially in education, casual games, and augmented reality projects using Unity 3D as the main development tool. He can be reached via thetnswe@gmail.com. I would like to thank the whole team at Packt Publishing for keeping track of all the logistics and making sure the book was published no matter what; I really appreciate this. I'd also like to thank my parents for supporting me all these years and letting me pursue my dream of becoming a game developer. Without all your support, I wouldn't be here today. And finally, a huge thanks to my wife, May Thandar Aung, for allowing me to work on this book after office hours, late at night, and even on weekends. Without your understanding and support, this book would have been delayed for another year. I'm grateful to have your support in whatever I do. I love you.
About the Reviewers Mohammedun Bakir Bagasrawala is a Unity AI engineer at Beachhead Studio, an Activision Blizzard studio. He holds a master's degree in computer science with a specialization in game development from the University of Southern California. He worked at DreamWorks Animation, where he was part of the team that built innovative AI technologies. He then moved to Treyarch and had the utmost pleasure of working on Call of Duty: Black Ops 3, implementing several features of this game. Apart from his professional experience, he has also been an AI lead across a gamut of mobile, console, and board games at the USC GamePipe Laboratory. I would like to thank my parents, Shabbir and Rita; my siblings, Esmail and Jacklyn; and my best friend, Afreen, for helping me become who I am today. I would also like to thank Giselle, Pratik, Rushabh, Neel, Soham, Kashyap, Sabarish, and Alberto as they have stood by me throughout. Lastly, I would like to thank my former managers, Mark, Vishwa, Ryan, and Trevor and my professors, Artem and Michael Zyda. Adam Boyce is a software developer and an independent game developer who specializes in C# scripting, game design, and AI development. His experience includes application support, software development, and data architecture with various Canadian corporations. He was also the technical reviewer for Unity AI Programming Essentials, Packt Publishing. You can read his development blog at www.gameovertures.ca and follow him on Twitter at https://twitter.com/AdamBoyce4. I'd like to thank my wife, Gail, for supporting me throughout the review process and also in my life and career.
分享到:
收藏