Why KinematicBody2d doesn't move to the right, only to the left with standard Input.is_action_pressed?

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

Hi, guys, i have a weird issue on my platformer project: the kinematicbody2d is not moving to the right when it is on floor with the is_action_pressed comand. Here is the code:

extends KinematicBody2D

const GRAVITY=20
const SPEED=300
const JUMP=-600
const UP=Vector2(0,-1)
var motion=Vector2()

func _physics_process(delta):

if Input.is_action_pressed("ui_right"):
	if is_on_floor():
if Input.is_action_pressed("ui_left"):
	if is_on_floor():
elif is_on_floor():
if is_on_floor() and Input.is_action_just_pressed("ui_up"):
if is_on_floor() and Input.is_action_just_pressed("attack"):

if !is_on_floor():

:bust_in_silhouette: Reply From: hilfazer

This code

elif is_on_floor():

will be called if "ui_left" action is not pressed, regardless of "ui_right".

Use elif in this line:

if Input.is_action_pressed("ui_left"):

Sorry, but it still doesn’t work or maybe i don’t get it. Could you write the line for example? Thank you for your help.

cristixxx | 2018-03-10 10:22

This line

elif Input.is_action_pressed("ui_left"):

instead of this one

if Input.is_action_pressed("ui_left"):

hilfazer | 2018-03-10 10:28

It works, thanks.

cristixxx | 2018-03-10 11:38