Procedural Content Generation for Unity Game Development

Book description

Harness the power of procedural content generation to design unique games with Unity

About This Book

  • Learn the basics of PCG development
  • Develop a 2D game from start to finish
  • Explore all the different ways PCG can be applied in games

Who This Book Is For

This book is for Unity game developers, especially those who work on indie games. You should be familiar with Unity and C# scripting but you'll be able to jump in and start learning PCG straightaway.

What You Will Learn

  • Understand the theory of Procedural Content Generation
  • Learn the uses of Pseudo Random Numbers
  • Create reusable algorithm designs for PCG
  • Evaluate the data structures for PCG
  • Develop smaller games with larger amounts of content
  • Generate content instead of spending time designing every minute detail
  • Learn when and how to add PCG to your game
  • Learn the fundamental techniques of PCG

In Detail

Procedural Content Generation is a process by which game content is developed using computer algorithms, rather than through the manual efforts of game developers. This book teaches readers how to develop algorithms for procedural generation that they can use in their own games. These concepts are put into practice using C# and Unity is used as the game development engine.

This book provides the fundamentals of learning and continued learning using PCG. You'll discover the theory of PCG and the mighty Pseudo Random Number Generator. Random numbers such as die rolls and card drafting provide the chance factor that makes games fun and supplies spontaneity. This book also takes you through the full development of a 2D game.

Starting with level generation, you'll learn how PCG can make the game environment for you. You'll move into item generation and learn the different techniques to procedurally create game items. Thereafter, you'll be guided through the more abstract PCG areas such as scaling difficulty to the player and even generating music! The book helps you set up systems within your games where algorithms create computationally generated levels, art assets, quests, stories, characters, and weapons; these can substantially reduce the burden of manually creating every aspect of the game.

Finally, you'll get to try out your new PCG skills on 3D terrain generation.

Style and approach

An easy-to-follow, project-based guide that will let you build a complete game by the end of the book using PCG.

Table of contents

  1. Procedural Content Generation for Unity Game Development
    1. Table of Contents
    2. Procedural Content Generation for Unity Game Development
    3. Credits
    4. Disclaimer
    5. About the Author
    6. About the Reviewers
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    8. 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
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    9. 1. Pseudo Random Numbers
      1. Introducing PCG
      2. Usage of PCG
      3. Application of PCG
      4. Pseudo random numbers
      5. Random versus pseudo random numbers
        1. PRNs in PCG
          1. Random Hello World
          2. Classic Hello World
          3. PCG Hello World
      6. Challenge
      7. Summary
    10. 2. Roguelike Games
      1. An introduction to Roguelike games
      2. Why Roguelike?
      3. Our own Roguelike project
      4. Setting up the project
        1. Importing the base project
        2. File overview
        3. Animation
          1. Fonts
          2. Prefabs
          3. Scenes
          4. Scripts
      5. Summary
    11. 3. Generating an Endless World
      1. Data structure choice
        1. Array
        2. Linked list
        3. Dictionary
      2. PCG algorithm overview
      3. Scene setup
        1. Player positioning
        2. Camera following
        3. Layers
      4. Initial Game Board
        1. Connecting code
        2. The PCG Game Board
      5. Summary
    12. 4. Generating Random Dungeons
      1. Algorithm design
        1. Algorithm overview
        2. The grid
        3. Essential path
        4. Random path and chambers
        5. Filling in the rest of the gird
        6. Placing the entrance and exit
        7. Algorithm summary
      2. Data structures
        1. Back to the map
        2. Queue
        3. Prefab setup
        4. An exit sign
      3. DungeonManager
      4. BoardManager
      5. Player
      6. GameManager
      7. Back to the Unity Editor
      8. Seeding the dungeon
      9. Challenge
      10. Summary
    13. 5. Randomized Items
      1. Generating health items in the game world
        1. Implementing health item generation
          1. Setting up sprites
      2. Generating items in the dungeon
        1. The Chest prefab
        2. Chest implementation
        3. Spawning the chest
        4. The Item prefab
        5. Item code
        6. Adding player to item interaction
      3. Summary
    14. 6. Generating Modular Weapons
      1. PCG with modules
        1. Statistics of modular PCG
        2. Creating and configuring new sprites
        3. Creating a multiple image prefab
      2. Modular weapon scripts
      3. Adding a spawn point
      4. Adding a weapon pick up
      5. Adding scripted weapon animation
      6. Adding character facing directions
      7. Summary
    15. 7. Adaptive Difficulty
      1. Setting up sprites
      2. Adding enemies to the world board
      3. Adding enemies to the Dungeon Board
      4. Fighting the enemy
      5. Adaptive difficulty
        1. Enemy AI
        2. Finishing up
      6. Summary
    16. 8. Generating Music
      1. Concept of music
        1. Tempo
        2. Melody
        3. Repetition
          1. Procedurally generated music algorithm
          2. Measure
          3. Dividing the measure
        4. The base line
          1. Setting up the script
          2. The Sound Manager script
        5. Adding tension
      2. Summary
    17. 9. Generating a 3D Planet
      1. Adding a third dimension
        1. 3D versus 2D
        2. Know your geometry
        3. Working with the Unity primitive sphere
        4. Generating a sphere
        5. Adding randomization
        6. Bad time and space complexities
      2. Multi mesh planet
      3. Exploring the planet
      4. Summary
    18. 10. Generating the Future
      1. Models
      2. Items
      3. Levels
      4. Texture
      5. Terrain
      6. Physics
      7. Animation
      8. AI
      9. Story
      10. The player sandbox
      11. Summary
    19. Index

Product information

  • Title: Procedural Content Generation for Unity Game Development
  • Author(s): Ryan Watkins
  • Release date: January 2016
  • Publisher(s): Packt Publishing
  • ISBN: 9781785287473