Monday, 4 August 2014

Super Simple And Basic Mini-Map Tutorial

These days most games have a mini-map in the bottom corner of the screen which gives the player a rough idea of what is going on in the area around them, this tutorial will show you how to create a very basic mini-map in Unity.

To start off this tutorial you need to add a new camera to the scene. To do this select the "GameObject" option from the top of the screen, scroll down to "create other" and then select camera from the list. 
















This will add a new camera to the scene. This camera will work as your mini-map. Now you have the second camera in the scene you need to position it so that it creates the same view as a normal mini-map. Use the three different coloured arrows around the camera to move the camera into position. Position the camera above the player at a distance you are happy with and then rotate the camera along the X axis so that the camera is facing the player. 




These are the arrows you will need to use to position the camera in the scene.






The easiest way to change the rotation of the camera is to highlight the value of the axis that you want to change and then type in your own value. 

The preview on your second camera should now look something like this:












If you already have a camera set up for your player Unity will only render that camera. To make it so that your mini-map camera is rendered you will need to change the depth setting of the camera. Left click on your mini-map camera in the hierarchy panel, doing this should bring up a "Inspector" panel on the right side of the screen. 
























Near the bottom of the inspector panel there is an option which says "depth". 




Delete the value shown in this box and replace it with a "1". This now means that Unity will render your mini-map camera instead of the player camera. Now you need to change the size of the mini-map viewport to make it a bit more of a mini-map. Directly above the "Depth" property is a "Viewport Rect" property. To make the mini-map smaller you will need to change the W and H values of the Viewport Rect property. The "W" value will change the width of the mini-map and the "H" value will change the height of the mini-map. Hover your cursor over each of the letters and then click and drag left or right to change the value. To get a better view of what is happening to your mini-map click on the "game" tab at the top of the screen, this will show you what your view will look like during gameplay and will allow you to see the size of your mini-map. 

Once the mini-map is set to a size that your are happy with you can move onto the final few steps for the tutorial. Next up you will need to change the projection of your camera to orthographic. Scroll down the inspector menu located on the right side of the screen until you find the "Projection" property. 

























Click on where it says Perspective and select orthographic from the drop down menu that pops up. Now the camera is set up you may want to adjust the size value which has replaced the field of view slider. Changing the size value will have the same effect as changing the field of view slide. Now for the final step. The last thing you need to do is make the mini-map camera a child of your player object. In the hierarchy drag and drop the camera onto your player object, this will make it a child of your player. Having the mini-map camera as a child of the player means that every time the player moves around, the camera will follow them. If your game has any pop-up text elements that you want the player to see at all times make sure you set the "layer" that each of these are on to "UI", once that is set click on the culling mask of the mini-map camera and then click on the "UI" option from the drop down menu. This will make it so that the text elements will only be visible on the main camera and will not obstruct the view on the mini-map. 

Switch the layer that your pop-up text is on using this option and then click on the box shown below to change it so that the mini-map camera won't render that text.























Please keep in mind that this tutorial is only to create an extremely simple mini-map without using any scripts. If you have any trouble with the tutorial be sure to leave a comment or contact me on twitter. 

No comments:

Post a Comment