# moving left and jumping not working correctly Attention Topic was automatically imported from the old Question2Answer platform. Asked By rodell2020

i am using god 3.5 windows 10
2D platformer game.
here is my code

enum States {AIR = 1, FLOOR, LADDER, WALL}
var state = States.AIR
var velocity = Vector2(0,0)
var is_jumping = true

const SPEED = 210
const GRAVITY = 35
const JUMPFORCE = -1100

func _physics_process(delta):
match state:
States.AIR:
if is_on_floor():
state = States.FLOOR
continue
\$Sprite.play(“Air”)
if Input.is_action_pressed(“Right”):
velocity.x = SPEED
\$Sprite.flip_h = false
elif Input.is_action_pressed(“Left”):
velocity.x = SPEED
\$Sprite.flip_h = true
else:
velocity.x = lerp(velocity.x,0,0.2)
move_and_fall()
States.FLOOR:
if not is_on_floor():
state = States.AIR
if Input.is_action_pressed(“Right”):
velocity.x = SPEED
\$Sprite.play(“Walk”)
\$Sprite.flip_h = false
elif Input.is_action_pressed(“Left”):
velocity.x = -SPEED
\$Sprite.play(“Walk”)
\$Sprite.flip_h = true
else:
\$Sprite.play(“Idle”)
velocity.x = lerp(velocity.x, 0,0.2)

``````			if Input.is_action_just_pressed("Jump"):
velocity.y = JUMPFORCE
\$SoundJump.play()
state = States.AIR

move_and_fall()
``````

func move_and_fall():
velocity.y = velocity.y + GRAVITY
var snap = Vector2.DOWN * 32 if !is_jumping else Vector2.ZERO
velocity = move_and_slide_with_snap(velocity, snap, Vector2.UP)

when I run the level I can walk in both directions and jump straight up
and walk to the right and jump at the same time

but when I try to walk to the left and jump at the same time it jumps me back to the rigt

I fixed it
I took out var is_jumping = true and the line

var snap = Vector2.DOWN * 32 if !isjumping else Vector2.ZERO

and changed
velocity = move_and_slide_with_snap(velocity, snap, Vector2.UP)
to
velocity = move_and_slide(velocity,Vectore2.UP)

and change
elif Input.isactionpressed(“Left”):
velocity.x = SPEED

to
elif Input.isactionpressed(“Left”):
velocity.x = -SPEED

rodell2020 | 2022-07-02 05:05 Reply From: SteveSmith

Take out var is_jumping = true and the line

var snap = Vector2.DOWN * 32 if !isjumping else Vector2.ZERO

and change
velocity = moveandslidewithsnap(velocity, snap, Vector2.UP)
to
velocity = moveandslide(velocity,Vectore2.UP)

and change
elif Input.isactionpressed(“Left”):
velocity.x = SPEED

to
elif Input.isactionpressed(“Left”):
velocity.x = -SPEED