#Move Player 4-directions

3 messages · Page 1 of 1 (latest)

knotty yew
#

I want to move my 2d player object in 4 directions. It's currently possible to move it all 8 directions. How can i do this?

thin fjord
#

You won't want to use get_vector for this. You'll need to decide which axis to prioritize, x or y, and then handle them separately

silk stratus
#

Something like this :

    var direction: Vector2 = Vector2.ZERO
    if Input.is_action_pressed("move_left"): direction = Vector2.LEFT
    elif Input.is_action_pressed("move_right"): direction = Vector2.RIGHT
    elif Input.is_action_pressed("move_up"): direction = Vector2.UP
    elif Input.is_action_pressed("move_down"): direction = Vector2.DOWN
    velocity = direction * speed```