How do I turn off strafing (moving in the air)?

Godot Version


i’m making my first ever game and I’m trying to stop my character from moving in the air. I want the character to keep the velocity of the jump too. I’ve tried using

if not is_on_floor():
velocity.x = 0
velocity.z = 0

but it had no effect.

I would take your movement code, and only change velocity when they are on the floor. Something like this?

if is_on_floor():
    if Input.is_action_pressed("move_right"):
        velocity.x = SPEED
    elif Input.is_action_pressed("move_left"):
        velocity.x = -SPEED
    if Input.is_action_pressed("jump"):
        velocity.y = JUMP_VELOCITY
1 Like

that’s actually a very simple solution how did i not think of that!? thank you very much :3