Godot Version
v4.7.1
Question
Let’s say you have the player in the Main Menu, sitting on one side of the screen. Once the game starts, you would want the camera to switch smoothly to the player such that the player becomes the center of the screen.
It doesn’t seem to be a way of manipulating Camera2D initial position since the class does not expose such methods.
How would one attempt to solve this challenge?
Animate camera’s position using a tween.
The cameras initial position is wherever you put your camera when the game starts. If you place the camera as a node in your screen, then the initial position is wherever you put the camera.
If you add it as a child in code, then it’s wherever you set it’s global_position first, otherwise it’s 0,0.
That won’t work. If I modify the global position, the camera won’t smoothly center on the player again, it will simply have an persistent offset from the player.
How else would you want to modify the cameras initial position? I don’t really understand the problem. And as @normalized already said, you can simply use a tween to animate the cameras position.
A tween seems hacky, since Camera2D already has smoothing implemented.
Forget about the initial camera position. The idea is that I simply want the camera to start smoothly follow the player from an initial offcentered position.
Use camera’s offset property and tween it to zero.
I found a decent solution myself. I can add a Node2D myself with a child Camera2D node. The Node2D acts as an artificial target for the Camera2D.
This allows me to set an initial position to the Node2D. Then, whenever I want to start following a target, I simply set the Node2D global position to the target’s position, in my case, the player position.
This approach also allows for simple future camera target change.
Using offset is simpler though.
could you detail on how? Camera2D has built in smoothing + other behaviours. Adding a tween will simply discredit all that, if I understand correctly.