Pizza Pursuit: How to Create City Layout

In our previous post, we kicked off our development of our pizza delivery game. Here is the game design document and the code. In this post, we are creating the city that we will drive around. We will lay out the buildings and the roads, and we will create and adjust the colliders to allow us to navigate.

For this project, we are using roads from Kenney and Simplepoly City.

Unity File Formats

Unity supports many different file formats for importing assets. Importantly for us, Unity supports importing Blender files.

Export the Object from Blender

All of the buildings in Simplepoly City are in one blend file. Therefore, we need to export each of the buildings we want to use. The general steps we follow:

  • Create a new blend file.
  • Delete everything in the scene.
  • Append one of the buildings to the scene. Click File->Append(double click on the blend file, select the object folder, click on the name of the building that you want to append).
  • Move the object to the center of the scene. This will ensure that when we add the object in Unity, it will be at (0,0,0). To move to the center, select the object and press the object tab in the properties on the right. Change the Location X, Y, and Z location to 0.
  • I also like to apply the rotation (Ctrl-a -> rotation). Applying the rotation “resets” the rotation to 0 while keeping the object visually in the same place.
  • Save the building into the Unity project asset folder.

Import Object into Unity

Placing a Blender file into the Asset folder will automatically import it into Unity. Once in Unity, I do a few things. 

  • Create an empty Game Object in the scene. 
  • Drag the model onto the object. 
  • Add a collider to the object. I tend to use two different colliders. For most buildings, I use a box collider. This is a very simple collider and very fast for Unity. If the base of the building is more complicated, a box collider may not work. Therefore, we may need to use a mesh collider. Note that the mesh collider must be on the mesh itself. 
  • Once I have a collider, I drag the object into my prefab folder. Creating a prefab makes it easy to reuse the asset.

With the prefabs created, now we can lay out the city. I created the roads first.

Next, I added a plane that the buildings will sit on (GameObject->3D Object->Plane).

Finally, added the buildings.

Test Drive

Now that we have the city, let’s take our car for a spin.

One Comment

Comments are closed.