[Tutorial] Creating a Mini-Map From Scratch

Hey Guys! I figured I would document my process for creating a Mini Map for the Game Tutorial. I've made this kind of map in bare Unity before, but making it work in ORK required some changes to the process! Special thanks to Shadow_Fire for pointing me to the right node. Here we go!

Step One: Setting up in the Hierarchy

1a) There are a couple things you need to create ahead of time so you can put them together. In the project folder, under Assets=>Materials folder, you want to create a 'Custom Render Texture'. Rename it to "mapDisplayTexture".

1b) While you are in the Materials folder, you can also create a new Material, set the shader to 'Unlit/color' and the Main Color to a nice bright blue. Name the Material "mapPlayerMat".

1c) Next, in your Town Scene, create an empty Game Object and name it MapCam. Place it at ground level somewhere around the town entrance.

1d) Add a New C# Script component to the Game Object and name it "camera_ControllerScript". Doubleclick the script to open in MonoDevelop (Visual Studio).

The variable of Quaternion type stores the game object's current rotation at game start, and then every frame the game object's rotation is re-set to that initial rotation. Which means when the MapCam is attached to a player, the player can turn every which way, but the map will still be oriented with forward as 'north'.

1e) Create a Camera as a child of MapCam. The camera settings are as follows.Position (x0,y20,z0), Rotation (x90,y0,z0) Clear Flags = Solid Color, Background = black, Culling Mask = Everything (for now). Projection = Orthographic, Size = 10. Target Texture, (this one is important) is set to the "mapDisplayTexture". This means that, instead of rendering to a screen every frame, it saves the render to the texture file, and overwrites it every frame, aka. in real time.

You can play with the y position of the camera to make sure the clip is above your trees and buildings, and the orthographic size until it is as far or close as you would like for your map view.

1f) Set the Transforms of your MapCam to Position (0,0,0) Rotation (0,0,0) Scale (1,1,1) and then drag the Game Object into your prefabs folder.

1g) Create a Sphere with a radius of 1.5 or 2. Name it "mapMarkerPlayer" and drag the mapPlayerMat material onto it to turn it bright blue. With the sphere selected, click on the Layer dropdown under its name in the Inspector and go down to 'Add Layer'. Name the new layer "mapMarker" and assign the sphere to that Layer. Now, only cameras and lights set to interact with the 'mapMaker' layer can see or effect the sphere. It will be invisible to cameras where this layer is not checked in the Culling Mask dropdown in camera settings.

Zero out the transforms by rightclicking the cogwheel icon at the far right of the Transform component in the Inspector and selecting reset. Drag mapMarkerPlayer into Prefabs.

Step Two: Menu Framework

2a) Open Ork Framework and move to Base/Control = Input Keys. Create a new key, name it "Map" and set the input origin to Key Code and your Positive and Negative fields to M (you can change this to fit your own game's control schema, M is just far enough away from WASD to avoid an accidental hit)

Display Conditions:Ignore all the way down to Battle Types, which is No. Menu Screens = No.

Image Settings:Here's where we put that lovely texture we made to work. Click the Add Foreground Image button. Set Image Bounds to (w250,h250) and Use Image to Selected. Click the select button on the review window and select your mapDisplayTexture (or just drag it from the project list). Scale Mode can be set to "Scale To Fit" or "Scale And Crop" There should not be too much distortion here.

Step Three: Adding to the Player

You can, of course, just add the 'MapCam' and 'mapMarkerPlayer' to your player character prefab manually, but if you plan to switch which character might be player controlled, the following should be more elegant.

Change Culling Mask = selectedCulling mask dropdown, if you click on the mapMarker layer, the checkmark next to it should disappear, meaning the camera will no longer see things on that layer.

Save this Event as "cameraMaskNoMaps"

3c) Navigate to World => Global Events. Create a new Event and name it "Main Camera Settings". Set the Event Asset to 'cameraMaskNoMaps' and then for event Type select Scene. The other settings are fine, but you can fuss with when in a scene the event will run. I left it to "All"

3d) Create a second new Global Event and name it "MapCameraSetup". Set the Event Asset to 'mountMapCamToPlayer' and Event Type to Scene. This way the player will not lose their map when moving to a different zone.

Step Four: Differentiating the MiniMap

As it stands, the current Minimap shows exactly where the player is, from above, in the game world as it exists. You've succeeded! We have a map! But there's more we can to to change the visual appearance of the map

To make things more classical, you could add a Quad to each scene, under the ground terrain but exactly the same size, with a color and set to the mapMarker layer. Then wherever there is an object or terrain feature the player cannot walk through, add a Masking shape (quads are low poly) in black to define where the player cannot go. Changing your MapCam camera so the Culling Mask is set to only the mapMarker layer means you control what the map sees. Setting the Main Camera to never see the Mapmaker Layer means you don't have a bunch of blue spheres walking around.

This is also a away to create "secret" passages ala classic FF minimap. Just mask off an area that people can in fact move through so it's not obvious from the map view. You can add Masking shapes by hand, or attach them to building prefabs and the like, along with any door indicators you want the map to have. NPCs can be tagged with their own colored spheres (red for enemies, green for allies, etc) or you can mark them with icons to indicate quests or allegiances.

A slightly more sophisticated Mini Map that is actually easier in some ways to set up, is to take an orthographic screenshot of your finished scene from above, and take it into a graphics program to then draw a map over it, allowing you to define houses and staircases and trees artistically rather than just black masking, and putting that on the ground level quad. The player can still only go where the player can go in the scene, but the map has more character in light with whatever your game's visual style is.

Once you have a scene set up with the mapMarker layer, you can also create a Big Map Menu and a camera that is pulled back to show the whole zone.

@gamingislove Thank you for the tag! I forgot to add it as I was writing. I'll remember in the future.

@Shadow_Fire Thank you :) I love making tutorials, so there will probably be more. It's a great way to document my own process, and save others from having to completely reinvent the wheel. There are some other really great ones here!