#In a top-down gridless setup, how do i restrict the player's movement to only 4 directions?

1 messages · Page 1 of 1 (latest)

languid forum
#

Okay guys, this is the code:

    # Get player input
    var x_axis = Input.get_axis("left", "right")
    var y_axis = Input.get_axis("up","down")
    
    if x_axis != 0:
        y_axis = 0
    if y_axis != 0:
        x_axis = 0
    
    var input := Vector2 (x_axis, y_axis)
    
    # Move player
    if input != Vector2.ZERO:
        position += input * speed * delta
        animation_controller(input)
    else:
        $Anim.play("RESET")
    
    move_and_slide()```

This kinda restricts the player to move in a 4 way direction only, with the added bug of the movement code getting overwritten by the left / right keys if im pressing down or up, and the opposite not happening (the player will stay walking left / right even if i press up or down)
next mural
languid forum
#

@austere birch @bronze spear

bronze spear
#

Regarding the actions getting overridden, I don't think it's really possible to do that still in a simple way