This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

I created a walk script. Whenever my character is walking and i try to change direction, the character walks diagonally, before i release the button. How would I stop this from happening?


    if Input.is_action_pressed("Back"):
        velocity.y = -speed
        #$PlayerSprite.flip_h = false
    elif Input.is_action_just_released("Back"):
        var facing_back = true
        if facing_back == true:
            if Input.is_action_just_pressed("LoadAmmo"):
            if Input.is_action_just_pressed("SwordSwing"):

    elif Input.is_action_pressed("Forward"):
        velocity.y = speed
    elif Input.is_action_just_released("Forward"):
        var facing_forward = true
        if facing_forward == true:
            if Input.is_action_just_pressed("LoadAmmo"):

    elif Input.is_action_pressed("Left"):
        velocity.x = -speed
    elif Input.is_action_just_released("Left"):
        var facing_left = true
        if facing_left == true:
            if Input.is_action_just_pressed("LoadAmmo"):

    elif Input.is_action_pressed("Right"):
        velocity.x = +speed
    elif Input.is_action_just_released("Right"):
        var facing_right = true
        if facing_right == true:
            if Input.is_action_just_pressed("LoadAmmo"):


Basically, if you are only using 4 directions in your game then you should have this script layout (especially the _process). I recommend creating your own inputs.

func get_input():
    velocity = Vector2()
    if Input.is_action_pressed("ui_right"):
        velocity.x += 1
    elif Input.is_action_pressed("ui_left"):
        velocity.x -= 1
    elif Input.is_action_pressed("ui_down"):
        velocity.y += 1
    elif Input.is_action_pressed("ui_up"):
        velocity.y -= 1
    movement = velocity.normalized() * speed

func _process(delta):
in Engine by (309 points)
edited by

1 Answer

+1 vote
Best answer

Just a guess but maybe check for button up with not event.pressed so it does not happen 'before i release the button`

func _input(event: InputEvent) -> void:
    if event is InputEventMouseButton and not event.pressed:

Otherwise please provide more information or some example code please? You character only walks when button down? How does the turning work?

by (1,975 points)
selected by

Added script

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 Frequently asked questions and 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 [email protected] with your username.