my code will only make my kinematicbody2d move only once per press.

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

as the title says, while holding the directional button it will only move one, and not continually. here is my code and under the debugger says something but i cant seem to find the answer or figure out what they mean. i am new to coding so i would appreciate anything that can help me out, or direct me to a source that might be helpful in the future.

extends KinematicBody2D

var velocity = Vector2()

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

move_and_slide(velocity)
	
pass

W 0:00:10:0471 The function ‘move_and_slide()’ returns a value, but this value is never used.

KinematicBody2D.gd:14

W 0:00:10:0471 The argument ‘delta’ is never used in the function ‘_set_physics_process’.

KinematicBody2D.gd:5
:bust_in_silhouette: Reply From: Nophlock

The problem lies in the is_action_just_pressed cause this will only return true the first frame, the key got pressed and false afterward. What you should use instead is the is_action_pressed function.

Also see:

And:

it works :smiley: thanks :smiley:

deezy | 2019-08-26 15:46