Player movement is not smooth in pixel game

Godot Version

4.3

Context

I use CharacterBody2D for making my player in pixel game (320x180). When i move_and_slice() my player, it is not smooth anyway.
I turned off any snap thing in render 2D setting.

Here is my code when i move player:
image
image

Question

How to make the move smooth in pixel game?

Can you explain more? like with a video?

1 Like

Can you show the codes of the movement?

1 Like

What the codes is it? I am not sure what are you trying, can you try simple codes for a platformer? like this:

if not is_on_floor(): velocity.y += gravity * delta

if Input.is_action_pressed("jump") and is_on_floor():
    velocity.y = -300

var dir = Input.get_vector("ui_left", "ui_right")
velocity.x = dirr * 300

move_and_slide()

In physics process…

oh, i just try to use state machine for my game. So, maybe it’s hard to show you the whole thing here. I will try your code to see what happen.

1 Like

i tried, then i figure out that it is not the code problem.
In my game, i set texture_filter of character’s sprite to nearest, so it is not smooth.
When i set back to inherit or linear, then it is smooth but not pixel art (blur).
So, maybe there is no best solution for this one!

1 Like

Finnally, i found that player movement is not smooth because position is round() (i think). So i just use ceil() or floor() in process then it smooth.
The code is something like this (in player class):

sprite.global_position = global_position.ceil()