How to make a camera network in 2D

Godot Version

4.2.1 stable

Question

I want to make a system of multiple camera2D nodes where the player can swap what camera they are looking from rather than just a camera following the player. How can I achieve this?

The Camera2D node has make_current() which allows you to control which camera is active.

If you have multiple cameras in your scene, you can just map each camera to a unique index or button press. That part is up to you.

Incorrect according to the docs:

EDIT: This was a reply to @hydraware’s deleted post.

1 Like

Yeah I actually meant this function :see_no_evil:

1 Like

You could add all your cameras to a group then

var current_cam_num := 0

func _on_cam_switch() -> void:
	current_cam_num += 1
	current_cam_num %= get_tree().get_node_count_in_group("camera")
	get_tree().get_nodes_in_group("camera")[current_cam_num].make_current()

This line is so that you don’t get out of bound of the group’s max index and can loop back to the very first camera

current_cam_num %= get_tree().get_node_count_in_group("camera")