Camera2D jitter when moving the character

Godot Version

4.3

Question

When I move the character this camera jitter/hiccup happens. I tried moving the movement logic from _physics_process to _process but that doesn’t help.

I also tried:

  • to set the camera global position to character’s position,
  • have a camera as a child of the character
  • lock and unlock fps,
  • disable V-Sync,
  • try all the options in V-Sync Mode dropdown menu,

but none of these approaches fix the issue.

Check if you maybe have these settings enabled and turn them both OFF

  • rendering/2d/snap/snap_2d_transforms_to_pixel
  • rendering/2d/snap/snap_2d_vertices_to_pixel

I have experienced Camera problems if I enabled these 2.

1 Like

These were already off, I just tried turning them on and off, and there was no difference.

What is the cameras process_callback set to?
Since it is not always jittery (at least that’s how I make it out in the video), it could also be unrelated to the camera. Have you monitored the performance?

I tried setting the process_callback to Idle and Physics, but there is no difference, the issue still persists.

I monitored the fps, it’s stable all the time.

The problem is likely that your player movement is jittery. In you video only the background is ‘stuttering’, not the player itself.
How are you moving the player?
If you move the camera independent of the player, do you also get the stutters?

Moving the camera outside of the player and smoothing it might help. You could also look into physics interpolation (Physics Interpolation — Godot Engine (latest) documentation in English). But since you are moving in _process anyways this should not make a difference.

This is my whole movement logic from gdquest tutorial:

func _process(_delta: float) -> void:
	
	direction = Vector2(
		Input.get_action_strength("right") - Input.get_action_strength("left"),
		Input.get_action_strength("back") - Input.get_action_strength("forward")
	)

	if direction.length() > 1.0:
		direction = direction.normalized()

	velocity = speed * direction

	move_and_slide()

I tried doing this with the Camera2D outside of the player, with and without Position Smoothing:

@export var player: Node2D

func _process(delta: float) -> void:
	global_position = player.global_position

But the jitter doesn’t go away.

Perhaps try rounding both the camera position and the player position? This should be as simple as global_position = global_position.round().

Tried it but nothing, the jitter persists.

You could try to interpolate the position change of the camera instead of directly setting it. This should make the camera movement ‘smooth’.

You should also move the movement code back to _physics_process since move_and_slide does physics calculations. You can then optionally turn on physics interpolation to avoid jittering when physics ticks and frames are not in sync.