I have a KinematicBody2D, to move it I use the function move_and_slide(speed), where speed is a Vector2, and it has simple gravity:

var spd = 500
var acceleration = 10
var jmpSpd = 800
var GRAVITY = 1300
var speed = Vector2()

set_process(true)

func _process(delta):
if Input.is_action_pressed("btn_jump") and is_on_floor():
speed.y = -jmpSpd

var desiredSpeed = 0
if Input.is_action_pressed("btn_right"):
desiredSpeed = spd
elif Input.is_action_pressed("btn_left"):
desiredSpeed = -spd
speed.x += (desiredSpeed - speed.x)*acceleration*delta
speed.y += GRAVITY*delta

speed = move_and_slide(speed)

The problem is that sometimes the player jumps higher than it should, and falls faster, and moves faster, this generally only happens when I have just turned on my computer, which makes me think that it has something to do with the number of times _process(delta) is called, but I have no idea.
Maybe I should use move_and_slide(speed*delta), but then I would need very big values for all the variables, and when using move_and_slide(speed) I get results much more similar to Godot 2 (this tutorial).

What should I do?

in Engine
edited

Two problems:

1) You should not be using move_and_slide in _process(). Use _physics_process().
2) move_and_slide() uses pixels per second, so you should not multiply by delta

Per the docs for KinematicBody2D:

linearvelocity is a value in pixels per second. Unlike in for example moveand_collide, you should not multiply it with delta — this is done by the method.

by (21,313 points)
selected

Thanks! Now everything works out.

Thanks for this. I had the same problem (called move_and_slide in _process instead of _process_physics) and everything worked fine ... except on one dev machine (laptop) where the player moved in slow motion.