0 votes


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

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();

        sprite2dPos.x += 1;
        trans3d.x += 1;
        sprite2dPos.x -= 1;
        trans3d.x -= 1;

        sprite2dPos.y -= 1;
        trans3d.y += 1;
        sprite2dPos.y += 1;
        trans3d.y -= 1;


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

(Godot 3.2.1 standard 64bit, win10)

Thank you!

asked May 10 in Engine by bruteforce (646 points)
retagged May 11 by bruteforce

1 Answer

0 votes

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!

answered May 15 by bruteforce (646 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.