0 votes

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?

asked Oct 10, 2017 in Engine by robrtsql (15 points)

2 Answers

0 votes
Best answer

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

answered Oct 10, 2017 by mateusak (1,071 points)
selected Oct 11, 2017 by robrtsql

That was the problem--I wasn't calling .align(). Good catch!

+1 vote

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)!

answered Oct 10, 2017 by bruteforce (646 points)
edited Oct 10, 2017 by bruteforce
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.