How do I sync the camera3D with the main camera2D?

Hi!

I want to use the 3D models as the background and also move the Camera3D along with the Camera2D.

My main issue is that my main camera2d resists under the player, which resists in another node.
However, the 3d background scenes are located somewhere above:

LEVEL_01
|------ Game
|------------|-------Player
|------------|-----------|--------Camera2D
|
|------ SubViewportContainer
|------------|-------SubViewport
|------------|-----------|-------Camera3D
|------------|-----------|-------MeshInstance3D

Q: How do I sync the camera3D?

It should just follow the Y and X positions of Camera2D. However, I do not know how to provide values across the different nodes.

Any suggetions?

So, you probably want to sync the position of the camera3D to the position of the camera2D, correct? I would just set the global position of the camera to the global position of the other camera. That should do it.

Note that these two properties have different types: Vector2 and Vector3, so you need to convert the first one to the second one. You may also need to multiply these with a factor depending on the model size, because 2D coordinates are usually “bigger” than 3D coordinates

1 Like

I would just set the global position of the camera to the global position of the other camera. That should do it.

Where and how exactly?

You’ll need to write a script that does it.

Yes, but how do I transfer the value from the node (Camera2D) to the other node (Camera3D) and update the value permanently?

Put the code in a _process() function that runs every frame.

1 Like

I’m kind of okay with that solution now:

extends Camera3D

@onready var camera2D: Node2D = $"../../../GAME/Player/Camera2D"


func _process(delta: float) -> void:
	global_position.x = camera2D.global_position.x/5000
	global_position.y = -camera2D.global_position.y/5000
	

Anyway, it’s so fiddly, and the viewport crops so much that I’m going to do without 3D and stick with 2D elements and more sprites instead. It’s not very resource-efficient, but it’s easier to manage in my game right now.