2D scene with 3D background: 3D camera movement

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

Hi!

I want to use 3D background (instead of parallax layers) in my 2D scene.
So I have a simple 2D scene (with player, Camera2D, platforms… etc.) and a CanvasLayer “background” that contains 3D objects (meshes, 3d camera… etc.).
When the player moves I want to change the 3D background’s cam position too!

I can do this with the camera’s set_translation function.
Now in my code if the player (and the 2D camera) moves 1 pixel in 2D, then the 3D camera moves 1 unit (???) in 3D.
In this way the 3D movement is too fast.
Of course I can decrease the values (ie. 0.5), but I don’t know the “right calculation formula”.

I uploaded the sample project: google drive

Screenshot:
enter image description here

The script:

extends Sprite

func _process(delta):
	var sprite2dPos = get_position();
	var cam3d = get_parent().get_node("3dLayer/spatial/cam3d");
	var trans3d = cam3d.get_translation();
	
	if(Input.is_action_pressed("ui_right")):
		sprite2dPos.x += 1;
		trans3d.x += 1;
	elif(Input.is_action_pressed("ui_left")):
		sprite2dPos.x -= 1;
		trans3d.x -= 1;
		
	if(Input.is_action_pressed("ui_up")):
		sprite2dPos.y -= 1;
		trans3d.y += 1;
	elif(Input.is_action_pressed("ui_down")):
		sprite2dPos.y += 1;
		trans3d.y -= 1;
		
	set_position(sprite2dPos);
	cam3d.set_translation(trans3d);

Can you help me, how to calculate the 3D camera’s position correctly?

(Godot 3.2.1 standard 64bit, win10)

Thank you!

:bust_in_silhouette: Reply From: bruteforce

I’ll try to rephrase my question (hard to explain… sorry).
I drew a simple example:
enter image description here
The distance is e.g. 10 pixels in 2D, and I need the corresponding distance in 3D.

How can I calulate this?

Thank you!