how can i fix my kinematicbody2d?

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

var velocity = Vector2()

# warning-ignore:unused_argument
func _physics_process(delta):
	velocity.y += 0
	
	
	if Input.is_action_just_pressed("ui_right"):
		velocity.x = 100
	elif Input.is_action_just_pressed("ui_left"):
		velocity.x = -100
	else:
		velocity.x = 0
			
# warning-ignore:return_value_discarded
	move_and_slide(velocity)
		
	pass

Note: I edited your post to fix the formatting. Please use the “Code Sample” button when posting so your code will be readable.

What is wrong? You asked for a “fix” but didn’t state the problem.

kidscancode | 2019-08-25 15:07

:bust_in_silhouette: Reply From: kidscancode

Since you didn’t state the problem, I can only guess, but I suspect your problem is this:

if Input.is_action_just_pressed("ui_right"):

Which should instead be:

if Input.is_action_pressed("ui_right"):

Using is_action_just_pressed() only counts the keypress on the frame in which you pressed it.