How to show smaller 2nd Camera from the same 2D viewport

Godot Version

v4.4.1.stable.official [49a5bc7b6]

Question

I have different characters on a topdown game. When I click on a character, their information is shown in a UI window. I’d like to show a 2nd camera (different from the main camera) that is zoomed in and focused on that character, in the UI.
I’m checking the subviewport but couldn’t figure out a way yet.

You need to use SubViewports indeed. Here’s my little demo:

This is the setup I made in my Player scene. The SecondCameraOffset is just the Node3D, where I want the Camera3D to be and then I just teleport the camera to that place on every frame. This is because anything inside the SubViewport has its transform reset, because a SubViewport doesn’t extend from Node3D, so the transform is lost.

1 Like

that did not work for me. I wonder if there is more setting needed or maybe related to 2D cameras?
In process, that’s what I added:
camera.global_position = camera_offset.global_position

Oh, I didn’t realize you’re working with 2D, sorry.
For 2D, you need to assign the World2D from your main scene to your SubViewport. Something like that in the SubViewport script should do the trick.

func _ready() -> void:
	world_2d = get_tree().current_scene.get_viewport().world_2d

1 Like