Godot Version
Godot 4.4.1
Question
Help is much appreciated!
Here’s a video showing the tilemap jitter when the player moves:
pixel-movement|video
Here are my relevant project settings (the ones I know):
window, stretch
- mode = canvas_items
- aspect = keep
- scale = 1.0
- scale mode = integer
rendering
- textures = nearest
- 2D, snap 2D transforms to pixel is on
And here is my player script:
extends CharacterBody2D
@export var walk_speed := 100
@export var run_speed := 200
@onready var sprite := $Sprite2D
var is_running := false
func _physics_process(delta: float) -> void:
# input handling
is_running = Input.is_action_pressed("run")
var current_speed = run_speed if is_running else walk_speed
velocity.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
velocity.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
velocity.y /= 2
velocity = velocity.normalized() * current_speed
move_and_slide()
I have a Camera2D on the player node:
- Texture filter = nearest
- scale is (1, 1)
- when this is working, I want to set the camera scale to (2, 2)
Did I miss anything else that’s relevant?
I’ve watched videos and tried various solutions without any luck. If I round the position after move_and_slide, the diagonal movement stops working.
Thanks so much for your help!
Can you share an example project with just the character, ground, and camera? I haven’t been able to mimic this issue myself.
1 Like
I’m not sure what kind of jitter you are referring to, I can’t see any in the video. But turning on snap 2D transforms to pixel can cause unsmooth movement.
If true, CanvasItem nodes will internally snap to full pixels. Useful for low-resolution pixel art games. Their position can still be sub-pixel, but the decimals will not have effect as the position is rounded. This can lead to a crisper appearance at the cost of less smooth movement, especially when Camera2D smoothing is enabled.
1 Like
Thanks so much to you both!
I’ve turned off Snap 2D Transforms to Pixel, and I changed the Process Callback property on my Camera2D node to Physics. That combo definitely improved things, but there is still some jitter when the player moves diagonally (WASD or arrow keys).
Here’s a link to the simple project as it stands now, just the ground, character, and camera: isometric-sandbox.zip - Google Drive
Thanks again for the offer to look!
2 Likes
Well with a keyboard there’s “jitter” if you don’t press or release the keys at the exact same time. At least that’s the only thing I can think of what you are referring to.
To test this theory if you change ui_down to ui_right in your script then move by pressing right to see if the jittering is still there or not.
If that is the case I think adding in acceleration and deceleration could make it less noticeable and probably the reason why in most games you wouldn’t notice this. If not that method somehow you could probably add buffer for pressing and releasing, which I never seen anyone do before.
1 Like