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.

Tried interpolating the camera, moving the code back to _physics_process and turning on physics interpolation but nothing fixes it.

Do I have to make such a radical decision to change the engine because of this? Because nothing manages to fix something so simple and rudimentary.

1 Like

I had the same issue and gave up on it in the end.

I was able to recreate the issue in a new project with nothing but a sprite and a camera with a fixed-speed movement script on it.

I don’t suppose you found a solution?

1 Like

I switched my project to 2.5D/HD-2D style because the Jolt3D physics engine was integrated in 4.4.

I did the following:

  • set physics/3d/physics_engine to Jolt Physics,
  • enabled physics/common/physics_interpolation,
  • set physics/common/physics_jitter_fix to 0.0,
  • set physics/jolt_physics_3d/simulation/velocity_steps to 20 and
  • physics/jolt_physics_3d/simulation/position_steps to 4

With all of that done, I don’t experience any jitter related to this issue, but the 2D engine is the same as before, this only fixed the 3D engine jitter, not 2D.

Edit:
If this is of any help, these videos explain how you could pull off 2D in 3D engine and the benefits of that approach:

1 Like

Thanks so much for the quick reply.

It’s hard to believe it’s not possible to pan a camera2d across a scene without intermittent stuttering, especially now that there’s 2d interpolation,
but I really appreciate you taking the time to detail your approach and solution.

1 Like

No problem, but yeah, it’s hard to believe that such basic stuff is not working properly, I hope they’ll fix this soon.

1 Like