Objective: To create a Minimap feature for my 3D Pacman game in Unity.
Currently I am partaking in a Game Dev challenge, and this particular challenge involves taking a classic game and putting a twist on it. My idea was to recreate Pac Man but in a 3D first person environment. However, I wanted to retain some of the games nostalgia and one of the ideas was to create a Minimap in the corner of the screen that would show the real time 3D environment in a top-down view, similar to a 2D view of the original. This would also give the player an advantage and show where the ghosts are running around on the screen.
Step 1 — Create a Second Camera for the Minimap Camera
Before we add a new Camera to the Hierarchy, let’s create a new parent empty game object to hold this:
Right click in Hierarchy → Create Empty → Name: Minimap Camera
Right click on this game object → Camera → Name: Minimap Cam
Step 2 — Configure the Minimap Camera
We need the camera to be above the 3D environment and facing down on the game objects so these are the Transform settings I have used.
Solid Color with a Black Background. It should look similar to this in your Scene view (with the black background):
For the Culling Mask options you want to add these 2 Layers (first) and then make sure they are the only Layer’s the camera is Rendering:
Step 3 — Create a Render Texture
In your Project window:
Right click → Create → Render Texture → Name: Minimap Render Texture
We now need to assign this Render Texture to the “Target Texture” field on the Camera component settings:
Step 4— Create the Minimap UI Element
We now need to create a UI element that we can project this Render Texture onto.
Right click in Hierarchy → UI → Raw Image.
This will automatically create a Canvas as the parent Game Object with the RawImage Game Object as a child.
These were my settings, but just make sure the “Render Mode” is set to - Screen Space Overlay.
These were my settings. The key take away for this is to make sure that the “Texture” has been assigned as the Minimap Render Texture we created.
Step 5— Setting GameObjects in the Scene to be the correct Layer
Taking a look back at Step 2 when we created the Layers — ‘Minimap’ & ‘Walls’, we now want to make sure that the GameObjects in our scene that we want rendered have the appropriate Layers.
For me I want to make sure that all of my Walls are set to the Layer — ‘Walls’.
For all my other GameObjects that I want rendered I will set the Layers to be — ‘Minimap’. This includes my enemies, pellets, power pellets and portals.
To take a look at the difference of rendering Layers looks like, let’s take a look at what happens when we set the ‘Ground’ game object to the ‘Minimap’ Layer:
As you can see, making sure we have the the right GameObject Layers setup is crucial and makes the UI visuals strikingly different and the Players experience much better!
Part 02 will look at adding Minimap Icons.