Skip to main content

How to avoid artifacts with smoothed camera in pixel art games in Godot

I've recently picked-up godot again and I remembered pretty quickly just how painful it is to setup a pixel art game. I may be weird, but I'm pretty much only interested in making games with diagonal movement which breaks quiet a lot of things when it comes to pixel art games.

These are the settings I've settled on.

Project Settings

  • display/window/size/window_height_override: 1920
  • display/window/size/window_width_override: 1080
  • display/window/stretch/mode: canvas_items, even though it's technically not reccomended
  • display/window/stretch/scale: as appropriate, as long as it's a integer >= 1 (generally 3, 4, or 6)
  • display/window/stretch/scale_mode: integer
  • rendering/2d/snap/snap_2d_transforms_to_pixel: false, setting this to false IME makes everything very bad
  • rendering/2d/snap/snap_2d_vertices_to_pixel: false

Camera Settings

Enable 'Position Smoothing' in the Camera2D, with the preferred speed.

Attach a script to it with something along the lines of:

## in the _process() function
# target_position is probably the player node position, but YMMV
# this is frame rate independent lerp smoothing
global_position = global_position.lerp(target_position, 1.0 - exp(-delta*10))

For more on frame rate independent smoothing: https://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/ and this awesome talk here: https://www.youtube.com/watch?v=LSNQuFEDOyQ

For more on the settings: https://www.gdquest.com/library/pixel_art_setup_godot4/ and https://www.reddit.com/r/godot/comments/1hab9tb/how_i_setup_my_pixel_art_game_in_godot_4/