0 votes

Hello

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):

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

    #Jump
    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
        else:
            location.x = Walk_Speed

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

    #No Input
    else:
        location.x = 0

    #Gravity
    location.y += Gravity


    location = move_and_slide(location, UP)

Thanks, Ace : )

in Engine by (15 points)

1 Answer

+2 votes
Best answer

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)
https://drakeirving.github.io/MultiKeyDisplay/

by (7,860 points)
selected by

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

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.