How to create real time minimap?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Anutrix
:warning: Old Version Published before Godot 3 was released.

I just want a real time minimap in one part of screen where the user can see a larger part of world around main user. In other worlds, a second zoomed out camera in a smaller viewport.

:bust_in_silhouette: Reply From: Zylann

I did a search for “minimap”, and I see other users asked the same question: Search results for Minimap - Godot Engine - Q&A

Yup checked all those but those answers recommend static unchanging sprite as map. How do I get it in real-time i.e, which changes when my main player(Rigidbody2D+Camera2D) moves around?
So far a few answers did mention having multiple cameras or viewports but did not mention how to do it. Is there a way to get a viewport inside another viewport with same camera at different zoom levels?

Anutrix | 2017-04-12 08:10

There is basically two ways:

  1. Have a background, static or generated once, and draw dots or minisprites on top of it. It is cheaper because you don’t need to draw the whole world twice, but needs a bit more code.

  2. Using a secondary viewport that renders the world zoomed out. That one is easier but can be performance-hungry depending on how many things your world contains. Also, it might not look exactly like you expect, for example you usually want to see clearly on the minimap, but because it’s just a zoomed-out viewport you’ll see a tiny pixel mash of the real world, not always good to distinguish objects.

You can take these two approaches and try what is best for you, because there is no “best” solution and it depends a lot on what you want to do exactly, not all minimaps are the same.

For a minimap that really renders the world a second time, you actually need two viewports:
One that renders the world, and ONLY the world (not the GUI),
One that renders the same world but on a smaller rectangle (the minimap).
The first viewport will have your game world as a child, with one camera for the player and another one for the minimap.
For the complete setup you can have a look at the the split-screen example, that you can find here:
Why split-screen? Well, your minimap is like a second screen then^^
Take your time to understand (I’m discovering it too btw), it requires a bit of scripting and tinkering with the options, but if you really want to draw the world twice, that’s what you are looking for.

Zylann | 2017-04-12 20:06