You are previewing Unity 4.x Cookbook.

Unity 4.x Cookbook

Cover of Unity 4.x Cookbook by Chico Queiroz... Published by Packt Publishing
  1. Unity 4.x Cookbook
    1. Table of Contents
    2. Unity 4.x Cookbook
    3. Credits
    4. About the Authors
    5. About the Reviewers
      1. Support files, eBooks, discount offers and more
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
    8. 1. Getting Started with Unity 4.x
      1. Introduction
      2. Installing Unity 4.x
      3. Setting your preferences
      4. Understanding and optimizing the User Interface
      5. Saving assets created in Unity as Prefabs
      6. Discovering Unity's content
      7. Importing your own content
      8. Importing Unity packages into your project
      9. Importing custom packages into your project
      10. Exporting custom packages from your project
      11. Adding custom packages to Unity's quick list
      12. Using the Project browser
    9. 2. Using Cameras
      1. Introduction
      2. Creating a picture-in-picture effect
      3. Switching between multiple cameras
      4. Customizing the lens flare effect
      5. Making textures from screen content
      6. Zooming a telescopic camera
      7. Making an inspect camera
      8. Creating particle effects using Shuriken
      9. Displaying a mini-map
    10. 3. Creating Maps and Materials
      1. Introduction
      2. Creating a reflective material
      3. Creating a self-illuminated material
      4. Creating specular texture maps
      5. Creating transparency texture maps
      6. Using cookie textures to simulate a cloudy outdoor
      7. Creating a color selection dialog
      8. Combining textures in real time through the GUI
      9. Highlighting materials at mouse over
      10. Animating textures by looping through array of materials (for example, simulated video)
      11. Disabling culling for a material
    11. 4. Creating GUIs
      1. Introduction
      2. Displaying a digital clock
      3. Displaying an analogue clock
      4. Displaying a compass to show player direction
      5. Displaying a radar to indicate relative locations of objects
      6. Displaying images for corresponding integers
      7. Displaying images for corresponding floats and ranges
      8. Displaying a digital countdown timer
      9. Displaying a countdown timer graphically (5, 4, 3, 2, 1 – blast off)
      10. Displaying a countdown timer graphically as a pie-chart style clock
      11. Creating a message that fades away
      12. Displaying inventory texts for single object pickups
      13. Displaying inventory icons for single object pickups
      14. Managing inventories with a general purpose PickUp class
      15. Controlling the scrollbar with the mouse wheel
      16. Implementing custom mouse cursor icons
    12. 5. Controlling Animations
      1. Introduction
      2. Configuring a character's Avatar and Idle animation
      3. Moving your character with Root Motion and Blend Trees
      4. Mixing animations with Layers and Masks
      5. Overriding Root Motion via script
      6. Adding rigid props to animated characters
      7. Making an animated character throw an object
      8. Applying ragdoll physics to a character
      9. Rotating the character's torso to aim
    13. 6. Playing and Manipulating Sounds
      1. Introduction
      2. Matching audio pitch to animation speed
      3. Adding customizable volume controls
      4. Simulating a tunnel environment with Reverb Zones
      5. Preventing the AudioClip from restarting if already playing
      6. Waiting for audio to finish before auto-destructing an object
      7. Making a dynamic soundtrack
    14. 7. Working with External Resource Files and Devices
      1. Introduction
      2. Loading external resource files – by Unity Default Resources
      3. Loading external resource files – by manually storing files in Unity's Resources folder
      4. Loading external resource files – by downloading files from the Internet
      5. Saving and loading player data – using static properties
      6. Saving and loading player data – using PlayerPrefs
      7. Saving screenshots from the game
      8. Control characters in Unity with the Microsoft Kinect using the Zigfu samples
      9. Animating your own characters with the Microsoft Kinect controller
      10. Homemade mocap by storing movements from the Microsoft Kinect controller
      11. Setting up a leaderboard using PHP/MySQL
    15. 8. Working with External Text Files and XML Data
      1. Introduction
      2. Loading external text files using the TextAsset public variable
      3. Loading external text files using C# file streams
      4. Saving external text files with C# file streams
      5. Loading and parsing external XML files
      6. Creating XML text data manually using XMLWriter
      7. Creating XML text data automatically through serialization
      8. Creating XML text files – saving XML directly to text files with XMLDocument.Save()
    16. 9. Managing Object States and Controlling Their Movements
      1. Introduction
      2. Controlling cube movement through player controls
      3. Controlling object look-at behavior
      4. Controlling object-to-object movements (seek, flee, follow at a distance)
      5. Controlling object group movement through flocking
      6. Firing objects by instantiation with forward velocity
      7. Finding a random spawn point
      8. Finding the nearest spawn point
      9. Following waypoints in a sequence
      10. Managing object behavior with states
      11. Managing complex object behavior with the state pattern
    17. 10. Improving Games with Extra Features and Optimization
      1. Introduction
      2. Pausing the game
      3. Implementing slow motion
      4. Implementing 3D stereography with polarized projection
      5. Preventing your game from running on unknown servers
      6. Identifying performance "bottlenecks" with code profiling
      7. Reducing the number of objects by destroying objects at a "death" time
      8. Reducing the number of enabled objects by disabling objects whenever possible
      9. Improving efficiency with delegates and events (and avoiding SendMessage!)
      10. Executing methods regularly but independent of frame rate with coroutines
      11. Spreading long computations over several frames with coroutines
      12. Caching, rather than component lookups and "reflection" over objects
    18. 11. Taking Advantage of Unity Pro
      1. Introduction
      2. Dynamically focusing objects with Depth of Field
      3. Creating a rearview mirror
      4. Playing videos inside a scene
      5. Simulating underwater ambience with audio filters
      6. Loading and playing external movie files
    19. Index
O'Reilly logo

Controlling object group movement through flocking

Realistic, natural looking flocking behavior (for example, birds, antelopes, or bats) can be created through creating collections of objects with the following four simple rules:

  • Separation: Avoid getting too close to neighbors
  • Avoid obstacles: Turn away from an obstacle which is immediately ahead
  • Alignment: Move in the direction the flock is heading
  • Cohesion: Move towards the location in the middle of the flock

Each member of the "flock" acts independently, but needs to know about the current heading and location of the members of its flock. This recipe shows you how to create a scene of flocking cubes. To keep things simple, we'll only implement basic versions of the last two rules of the preceding ...

The best content for your career. Discover unlimited learning on demand for around $1/day.