Menu

Unity3D – Simplest Circular Minimap and Minimap position update | Free Script | Part 2

2 Comments


This is part 2 of this tutorial. If you haven’t seen the first part, click HERE.

In this part, we’re going to do three things.

  1. Making the Minimap Circular
  2. Adding Minimap Boundary
  3. Updating Minimap position based on Player’s position

Setup:

I assume that you’re following this tutorial series from the beginning. So you’ve what we did in part 1.

Steps:

Making it Circular
  • Create Image GameObject and place it on top of Minimap Render Texture
  • Add a Mask component in Image GameObject and uncheck Show Mask Graphic
  • Make Minimap Render Texture a child of Image GameObject
Minimap Boundry
  • Add an Image GameObject as a child of Minimap Render Texture (inside canvas)
  • Stretch it throughout Render Texture
  • Assign a circular boundary (transparent sprite) to the newly created Image
Minimap position update
  • Create a new C# script named “SmoothFollow.cs”
using UnityEngine;
using System.Collections;

public class SmoothFollow : MonoBehaviour {
    
    public Transform Target;
    public float speed = 2.0f;
    
    void Update () {
        float Interpolation = speed * Time.deltaTime;
        Vector3 position = transform.position;

        position.x = Mathf.Lerp(transform.position.x, Target.position.x, Interpolation);
        position.y = Mathf.Lerp(transform.position.y, Target.position.y, Interpolation);
        position.z = Mathf.Lerp(transform.position.z, Target.position.z, Interpolation);
        
        transform.position = position;
    }
}

Download the Script HERE.

  • Assign this Script to your Minimap Camera
  • Then assign speed (maybe 2) and your Player GameObject to the Target field in Inspector panel
  • Now, wherever your Player goes, the Minimap will follow it smoothly with the speed you mentioned

That’s all for today.

Want to learn how to add Icons (Player, Enemy, etc) on the Minimap dynamically without Scripting? Click HERE.

Watch this tutorial step by step on YoutTube HERE.

Tags: , , , , , , , , , , , ,

2
Leave a Reply

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
SamChristian Hoo Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Christian Hoo
Guest
Christian Hoo

Thanks for the knowledge. appreciated

Sam
Guest
Sam

Nice tutorial

F