Unleash your creativity with procedural city generation in Unity

Find Saas Video Reviews — it's free
Saas Video Reviews
Makeup
Personal Care

Unleash your creativity with procedural city generation in Unity

Table of Contents

  1. Introduction
  2. The Algorithm for Procedural City Generation
  3. Generating a Grid-like Map
  4. Rotating Tiles for Different Configurations
  5. Collapsing Cells and Propagating Conditions
  6. Adding Complexity: Introducing City Blocks
  7. Diversity in City Blocks: Randomizing Building Prefabs
  8. Creating a Ring around the Tiles for Boundaries
  9. Scaling Up: Increasing the Number of Tile Options
  10. Finalizing the City Generation Process
  11. Additional Updates and Bug Fixes
  12. Rewarding Player Progression with a Formula
  13. Resolving AI Pathfinding Issues
  14. Publishing the Game on itch.io and Steam

The Algorithm for Procedural City Generation

Procedural generation is a powerful technique used in game development to create vast and dynamic worlds quickly. In this article, we will explore the algorithm known as wave function collapse, which can be used to generate entire cities procedurally. We will walk through the steps of the algorithm, from generating a grid-like map to adding complexity with city blocks and randomizing building prefabs. Along the way, we will address various challenges and bugs that may arise and discuss how to publish the game on platforms like itch.io and Steam.

Generating a Grid-like Map

To start with, let's understand the basics of generating a grid-like map. We will focus on a simpler example using three different tiles: grass, straight road, and curved road. The goal is to create a map where roads connect logically, and grass connects to grass. We'll assign labels to the sides of each tile to represent their properties. For instance, positive x will represent grass, negative x will represent road, and so on. By rotating and propagating these tiles, we can generate a grid that adheres to the defined rules.

Rotating Tiles for Different Configurations

As we introduce rotations to the tiles, the complexity of generating the grid increases. To avoid manual input of different rotations, we can write code to generate four copies of each tile, each with a different rotation. These copies will have a scriptable object that holds the rotation and side information. By doing so, we can avoid errors and ensure consistency in our algorithm.

Collapsing Cells and Propagating Conditions

Now, let's dive into the core of the wave function collapse algorithm: collapsing cells and propagating conditions. We start by randomly collapsing one grid placement and then propagate the new conditions to neighboring cells. For example, if a cell has grass on the positive x side, we remove prototypes that do not have a grass socket in their positive x to connect with the collapsed cell. This process repeats for all cells in contact with the collapsed cell. We then select the next cell to collapse based on the lowest entropy, which refers to the cell with the fewest options. This iterative process continues until all cells are collapsed, resulting in a completed grid with logically connected roads.

Adding Complexity: Introducing City Blocks

Now that we understand the basics, let's move on to generating entire city blocks. City blocks consist of larger prefabs such as intersections and turns. We also add multiple building prefabs to each block to introduce diversity. Each block randomly chooses a prefab upon generation, resulting in varied appearances for intersections and other structures. A ring is created around the tiles to prevent the player from walking out of the game world.

Diversity in City Blocks: Randomizing Building Prefabs

To add further variety to the city blocks, we attach a script that sets a random building prefab active upon generation. This ensures that not all intersections look the same. Although we would like to add more variety, time constraints may limit the number of building prefabs. Nevertheless, the current implementation already offers a good level of diversity.

Creating a Ring around the Tiles for Boundaries

To prevent the player from venturing beyond the city boundaries, we create a ring around the tiles. This ring consists of dead ends that act as barriers. By implementing this simple addition, we can ensure that the player stays within the boundaries of the game world.

Scaling Up: Increasing the Number of Tile Options

In order to create more intricate and immersive cities, we can increase the number of tile options. By expanding from the initial 12 options (grass, straight road, curved road) to a higher number, such as 32, we can introduce complex elements like intersections, bridges, and rivers. This expansion offers a wider range of possibilities for generating unique cities.

Finalizing the City Generation Process

With the procedural generation process in place, we can easily regenerate the grid with different dimensions, generating cities of varying sizes and complexity. By fine-tuning the algorithm and adding more tile options, we can create visually stunning and diverse cities that are suitable for our game world.

Additional Updates and Bug Fixes

In the final stages of development, it is crucial to address any outstanding bugs and make necessary updates to improve the overall gameplay experience. This may include addressing issues such as buildings obstructing the player's view, implementing sound effects for various actions, and adding background music to enhance the atmosphere. The article will explore the process of fixing these bugs and making updates to ensure a smooth and enjoyable gameplay experience.

Rewarding Player Progression with a Formula

To add an incentive for players to progress in the game, we will implement a formula to reward them based on their survival time. Rather than a simple linear function, we will design a formula that provides exponential rewards, gradually increasing as players survive longer. This will encourage players to strive for longer survival times and add an element of challenge to the game.

Resolving AI Pathfinding Issues

One of the challenges in game development is implementing efficient AI pathfinding. In our case, we encountered an issue where AI entities would get stuck behind buildings and struggle to pathfind towards the player. By optimizing the spawn zones and teleporting AI entities outside the player's field of view, we can solve this problem and ensure smooth AI movement and engagement.

Publishing the Game on itch.io and Steam

With the game development process complete, we now focus on publishing our game on platforms like itch.io and Steam. We will discuss the steps involved in setting up a store page, uploading the game files, and addressing any issues or feedback that may arise during the publication process. By leveraging these platforms, we can reach a wider audience and share our game with the gaming community.

Highlights

  • Exploring the wave function collapse algorithm for procedural city generation
  • Generating a grid-like map and rotating tiles for different configurations
  • Collapsing cells and propagating conditions to ensure logical road connections
  • Introducing city blocks and adding diversity with random building prefabs
  • Creating boundaries with a ring around the tiles
  • Scaling up the city generation process by increasing the number of tile options
  • Finalizing the city generation process for visually stunning cities
  • Addressing bugs, implementing sound effects, and adding background music
  • Rewarding player progression with an exponential formula
  • Resolving AI pathfinding issues for smooth movement
  • Publishing the game on platforms like itch.io and Steam for wider reach

Are you spending too much time on makeup and daily care?

Saas Video Reviews
1M+
Makeup
5M+
Personal care
800K+
WHY YOU SHOULD CHOOSE SaasVideoReviews

SaasVideoReviews has the world's largest selection of Saas Video Reviews to choose from, and each Saas Video Reviews has a large number of Saas Video Reviews, so you can choose Saas Video Reviews for Saas Video Reviews!

Browse More Content
Convert
Maker
Editor
Analyzer
Calculator
sample
Checker
Detector
Scrape
Summarize
Optimizer
Rewriter
Exporter
Extractor