- Edited
from https://docs.godotengine.org/en/stable/tutorials/physics/using_kinematic_body_2d.html :
try moving into the obstacle at an angle and you'll find that the obstacle acts like glue - it feels like the body gets stuck
This happens because there is no collision response. move_and_collide() stops the body's movement when a collision occurs. We need to code whatever response we want from the collision.
Use move_and_slide
. Let me fix your code:
extends KinematicBody2D
var speed = Vector2.ZERO
var maxspeed = 5000
var grav=200
var desped: float = 0.1 #from value 0.0 to 1.0 (max)
var acsped=50
func _ready():
pass # Replace with function body.
func _input(event):
if Input.is_action_pressed("ui_right"):
speed.x += acsped
if Input.is_action_pressed("ui_left"):
speed.x -= acsped
func _physics_process(delta):
clamp(speed.x, -maxspeed, maxspeed)
speed.x = lerp(speed.x, 0, desped)
speed.y = grav
speed = move_and_slide(speed)
print(speed)
EDIT: note that i did not use delta
, use it here speed = move_and_slide(speed * delta)
but then increase variable values (grav and acsped, I guess)