How to display a 3D object on screen(camera) space?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Afonso Lage

Hello folks!

I want to display a 3D object, a mini gizmo on the screen witch rotates with camera, acting like a compass. I tried to add a MeshInstance on a 2D node, but it didn’t work.

There is some kind of tutorial or some example that I can follow to do that?

:bust_in_silhouette: Reply From: johnygames

In fact, there is! The idea is to create two separate viewports, one containing your 2D world and the other containing the 3D compass. Then you place the 3D viewport at the bottom of the screen and you effectively create a 2D game with a 3D element on top.
Watch this:

It works in Godot 3.1 too, and you can rearrange the viewport container so that it enCOMPASSes the area that you want (pun intended). If it works better for you, you could also replace the HBoxContainer with a GridContainer. You replace the Node2D with a Spatial node that contains your item and you place the whole viewport where you want it to be. Then it is up to you to create the necessary logic for how to rotate your object.

Another radical idea, if you don’t want to use viewports, would be to set up your entire game in 3D using textured planes and have the compass be a regular 3D object at the bottom of the screen.

There may be more ways to go about this, but I do not know them.

Does this answer your question? If it does please mark this answer as best and upvote it.