Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jitter on player sprite during movement after enabling "Snap 2D Transform to Pixel" #71074

Open
Tracked by #86837
Tolly24 opened this issue Jan 8, 2023 · 1 comment

Comments

@Tolly24
Copy link

Tolly24 commented Jan 8, 2023

Godot version

4.0 beta8

System information

W10, GTX 1070, driver 527.56, Vulkan

Issue description

Recently upgraded to 4 and found out about the option "Snap 2D Transforms to Pixel" that replaced GPU pixel snap and how it should fix the known camera jitter when applying smoothing to a Camera2D. Enabling it does fix that but introduces sprite jittering that makes it look blurry and vibrating, reminds me of when you put move_and_slide() in _physics_process but not as violent.

I found an issue #63185 that seems to showcase this exact issue with video but for me, all the other sprites aren't jittering, it's only my player that the camera is following. My sprite's jitter is more intense that that of this person experiences but I think that's either because I have a faster move speed or due to camera smoothing they don't to use. Disabling smoothing however removes the issue completely but of course, I'd like to use it.

Steps to reproduce

In the minimal reprod steps below, you can find a demo project with these steps already done for you, make sure the snap setting is enabled though.

  1. Create a small 16x16 sprite, preferably fill it with a bright color and a black outline.
  2. New project
  3. Project Settings
    • Enable advanced settings
    • Under rendering / 2D, enable Snap 2D Transform to Pixel(can also enable snap vertices but it doesn't change anything for me)
  4. Create a 2D scene, change type to CharacterBody2D
  5. Attach a new script and add the code at the bottom. Add a sprite node set the sprite as the one created in step 1. Add a Camera2D too and enable "Current". Enable "Position Smoothing" and set its value to 15, then save the scene as "Player".
  6. Make a new 2D scene and optionally add a tilemap if you want
  7. Add the Player.tscn to the scene and run the game

Player.gd

extends CharacterBody2D
const ACCELERATION = 500
const MAX_RUNSPEED = 150
const MAX_WALKSPEED = 100
const FRICTION = 50000

func _physics_process(delta):
	var input_vector = Vector2.ZERO
	input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
	input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
	input_vector = input_vector.normalized()
	### RUN
	if input_vector != Vector2.ZERO && !Input.is_action_pressed("ui_walk") && !Input.is_action_pressed("ui_sprint"):
		velocity = velocity.move_toward(input_vector * MAX_RUNSPEED, FRICTION * delta) 
	###IDLE
	else:
		velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)

func _process(_delta):
	move_and_slide()

Minimal reproduction project

New Game Project.zip

@WhalesState
Copy link
Contributor

WhalesState commented Jul 31, 2023

I know this issue is annoying but you can avoid it in pixel perfect games by setting a small drag margin to your Camera2D and also by increasing the smooth speed of the camera if it still jitters. please confirm if this fixes the issue so i can open an issue to note this in docs.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants