So first off, you're calling move_and_collide
with a constant value. I know the docs can be a little bit fuzzy, but jump straight to the source and you'll see that it's not multiplying by delta for you. You're trying to move a constant amount per frame and frame times can vary. Instead you should want to move a constant amount per second, so you definitely want to multiply whatever you pass to move_and_collide
by delta if you're calling this from _process
. Ideally you'll want to multiply by delta if you call it from _physics_process
as well, since if you ever change your physics tick rate things will start moving at different speeds. In general you want to represent speeds in units per second and multiply by delta always.
This is a bit confusing, but the same is not true about move_and_slide
since it multiplies by delta for you and even more confusingly you don't even have to pass delta to it so you might not know that's happening. The move_and_slide
function uses the physics delta in 3.0 no matter what function you call it from and in 3.1 it checks to see if you're in _process
or _physics_process
and uses the correct delta. So move_and_slide
should work correctly in _process
after 3.1.
You should try this again in a build. I've been having trouble with the game stuttering a bit when run from the editor but being completely smooth in a build. I quickly rebuilt what you have and it does run choppy in editor, but smooth in a build using move_and_collide
in _process
. For reference, this is the script that runs smoothly.
extends KinematicBody2D
const SPEED = 100.0
func _physics_process(delta):
var input = Vector2()
input.x += float(Input.is_action_pressed('ui_right'))
input.x -= float(Input.is_action_pressed('ui_left'))
input.y -= float(Input.is_action_pressed('ui_up'))
input.y += float(Input.is_action_pressed('ui_down'))
if input.length() != 0:
input = input.normalized()
move_and_collide(input * SPEED * delta)
If you game has no dynamic bodies, everything should be fine calling these types of functions that move kinematic bodies around from the _process
function. This will produce the smoothest output and you won't even have to worry about the physics tick rate. Just know that you really can't change the physics threading model in the project settings if you're calling these functions from _process
.