if Input.isactionpressed("ui_right"):
$CollisionPolygon2D.scale = Vector2(1, 1)
$AnimatedSprite.flip_h = false
if on_ground == true:
vel.x = min(vel.x + acc, regSpeed)
$AnimatedSprite.play(walk)
else:
vel.x = min(vel.x + acc - 3, regSpeed)
$AnimatedSprite.play(idle)
elif Input.is_action_pressed("ui_left"):
$CollisionPolygon2D.scale = Vector2(-1, 1)
$AnimatedSprite.flip_h = true
if on_ground == true:
vel.x = max(vel.x + -acc, -regSpeed)
$AnimatedSprite.play(walk)
else:
vel.x = max(vel.x + -acc + 3, -regSpeed)
$AnimatedSprite.play(idle)
else:
vel.x = lerp(vel.x, 0 , 0.2)
$AnimatedSprite.play(idle)
if on_ground == true:
gravity = 10
idle = "idle"
$AnimatedSprite.offset = Vector2(0, 0)
#jump code
#regular jump
if Input.is_action_pressed("jump"):
if on_ground == true:
jump()
#if player releases jump key before max jump is reached, start falling
if Input.is_action_just_released("jump"):
jump_cut()
vel.y = min(vel.y + gravity, 350) #makes the player fall with gravity
vel = move_and_slide(vel, FLOOR) #makes the player move with coded physics