Why doesn't the camera follow my character exactly when moving around in _process()?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By robrtsql
:warning: Old Version Published before Godot 3 was released.

Example project: https://github.com/robrtsql/gamedev-projects/tree/3438188857fbbd475b10e7a1a6acba587fa1c5e3/CameraFollow

Godot 3.0 (built from source on master)
OS: Elementary OS 0.4.1 / Ubuntu (64-bit)
GPU: NVIDIA GeForce GTX 1070

I am troubleshooting an issue where my Camera2D node, which is a child of my sprite, doesn’t seem to be following its parent exactly.

My expectation is that, because Camera2D is a child of my Sprite, and the Camera2D’s offset is (0,0), then my Sprite should always be drawn in the center of the screen because the Camera2D’s position should always match that of the Sprite.

I have found that, when moving my sprite around in the physics process step, everything behaves as expected. (This is reproducible by changing this (https://github.com/robrtsql/gamedev-projects/blob/3438188857fbbd475b10e7a1a6acba587fa1c5e3/CameraFollow/Main.tscn#L13) to true).

However, when I move my sprite around in the regular process() step, the sprite is no longer drawn in the center of the screen.

What’s going on? My camera’s drag margins are all set to 0, and smoothing is turned off.

I didn’t include this script in the example project, but I have included scripts to force the global position of the Camera2D to be equal to that of my Sprite, but even after confirming that their positions are equal, the scene is still drawn in such a way that the Sprite is not guaranteed to be at the center (it visibly moves around).

Is my understanding incorrect? Why doesn’t my camera guarantee that my sprite is drawn in the center of the screen, and how can I fix this?

:bust_in_silhouette: Reply From: bruteforce

I am not familiar with 3.0, but in 2.* the Camera2D node has a current property. You should probably check it in the editor (or set it programmatically)!

:bust_in_silhouette: Reply From: mateusak

At the end of process() try using camera.align()

That was the problem–I wasn’t calling .align(). Good catch!

robrtsql | 2017-10-11 04:17