Player stutters at beginning of movement but after jumping it stops

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mayeshd

I have a problem. If i move the player with a or d it stutters at regular intervals. If i jump and still hold the buttons it stops until the player stops and this goes on and on.

extends KinematicBody2D

var velocity = Vector2(0,0)
const SPEED = 180
const JUMPFORCE = -300
const GRAVITY = 10

func _physics_process(delta):
if Input.is_action_pressed(“right”):
velocity.x = SPEED
if Input.is_action_pressed(“left”):
velocity.x = -SPEED

velocity.y = velocity.y + GRAVITY

if Input.is_action_just_pressed("jump") and is_on_floor():
	velocity.y = JUMPFORCE

velocity = move_and_slide(velocity,Vector2.UP)

velocity.x = lerp(velocity.x,0,0.2)

What is happening in your code when those buttons are released? Did you code that yet? If you use Input.is_action_pressed Then the behavior goes and continues after you hit that button. You should use Input.is_action_just_pressed Or even better Input.get_action_strength Or code an animation fix to Input.is_action_just_released. But try switching to Just pressed first and see if that helps.

SnapCracklins | 2022-04-26 20:14