#4 Directional Movement Input Update

1 messages · Page 1 of 1 (latest)

vivid bronze
#

A simple approach is to modify the direction vector before applying it to the velocity like so:

func player_movement():
    var move_direction := Input.get_vector("Left", "Right", "Up", "Down")

    if abs(move_direction.x) > abs(move_direction.y):
        move_direction.y = 0
    else:
        move_direction.x = 0

    velocity = move_direction * Speed 

    move_and_slide()
#

Just keep in mind that with this approach the Y-axis is prioritized (i.e. if you press up and left, you will just move up)

#

it's possible but you have to change your approach

vivid bronze
#

If you're using WASD for movement and press W and A, then the input vector will always be (-0.707, -0.707) regardless of if you pressed W or A first

#

So the solution involves tracking changes in the input vector