Wont Jump When Runing Left

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ace The Dolphin Guy


I am trying to making a simple 2D platformer with a run mechanic where if your press up the speed increases. When I jump while running to the right it works fine. But if I’m moving right while ruining and try to jump, the character won’t jump and just fall back down. I’m relatively new to coding and I’m not sure whats cause this behavior. Any help with explaining why this happens and what do do differently would be great!

Here is the script that does all the moment

extends KinematicBody2D
const UP = Vector2(0, -1)

export var Walk_Speed = 350
export var Run_Speed = 670
export var Gravity = 20
export var Jump_Force = 600

var location = Vector2()
var run = false

func _physics_process(delta):

    if Input.is_action_pressed("ui_up"):
	    run = true
	    run = false

    if is_on_floor():
	    if Input.is_action_pressed("ui_accept"):
		    location.y = -Jump_Force

    #Both Input
    if Input.is_action_pressed("ui_left") and Input.is_action_pressed("ui_right"):
	    location.x = 0

    #Right Input
    elif Input.is_action_pressed("ui_right"):
	    if run:
		location.x = Run_Speed
		    location.x = Walk_Speed

    #Left Input
    elif Input.is_action_pressed("ui_left"):
	    if run:
		    location.x = -Run_Speed
		    location.x = -Walk_Speed

    #No Input
	    location.x = 0

    location.y += Gravity

    location = move_and_slide(location, UP)

Thanks, Ace : )

:bust_in_silhouette: Reply From: eons

If your jump key is space, this is a hardware problem called “Keyboard ghosting”, you cannot avoid it with common keyboards, map your keys in a way to avoid this issue.
Is related to the way keyboard keys are wired.

Check this site to see keyboard combinations that won’t work (a common one is up+left+space)

Thanks : ) I changed all my inputs to wasd and controller and works just fine now : )

Ace The Dolphin Guy | 2018-12-20 06:33

Hi, you should select this as best answer if it solved your problem!

p7f | 2018-12-20 11:31