Godot Version
4.2.1
Question
In this clip, the character snaps to the left after moving for the first time and then does not jitter anymore afterwards. Any ideas how to fix this?
4.2.1
In this clip, the character snaps to the left after moving for the first time and then does not jitter anymore afterwards. Any ideas how to fix this?
It looks like it’s moving 1 pixel to the left.
Can you show your code? Do you have any snapping methods implemented? Is your character placed correctly? What if you move it a few pixels into the air, maybe it’s clipping the floor?
Here is a simplified version of the code (the problem still occurs with this code)
extends CharacterBody2D
const MAX_SPEED : float = 200
var gravity : float = 400
var acceleration: float = 1
var deceleration: float = 20
var character_direction : int = 0
enum State {Idle, Run, Jump, Vault}
var current_state : State = State.Idle
@onready var sprite : Sprite2D = $Sprite
func _physics_process(delta : float):
if !is_on_floor():
velocity.y += gravity * delta
var direction = Input.get_axis("left", "right")
if direction:
current_state = State.Run
if direction == sign(velocity.x):
velocity.x = move_toward(velocity.x, MAX_SPEED * direction, acceleration)
else:
velocity.x = move_toward(velocity.x, MAX_SPEED * direction, deceleration)
flip_character(direction)
else:
velocity.x = move_toward(velocity.x, MAX_SPEED * direction, deceleration)
move_and_slide()
func flip_character(direction : int):
sprite.flip_h = false if direction > 0 else true
character_direction = 1 if not sprite.flip_h else -1
I have not implemented any snapping methods myself, I’m just using the setting “Snap 2D Transforms to Pixel” and the problem does go away when I disable that (I do want to keep it enabled though)
I also did what you said and moved the character in the air and set gravity to 0 to see if the floor is causing it but the problem still happened even when moving in the air
Here’s more context just in case:
Viewport Width: 320
Viewport Height: 180
Window Width Override: 1280
Window Height Override: 720
Stretch Mode: viewport
Scale Mode: integer
Character Collision Size: 7 x 14
I updated to the latest version of Godot (4.4.1) and I’m not having the problem anymore. Thanks for the help though @wchc !
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.