try this :
extends KinematicBody2D
enum {
WATER,
GAS,
ICE
}
var velocity = Vector2(0,0)
const speed = 300
const gravity = 30
const jump = -700
var state = WATER
func physicsprocess(delta):
if Input.isactionpressed("right"):
velocity.x = speed
$Sprite.play("Walk")
$Sprite.fliph = false
elif Input.isactionpressed("left"):
velocity.x = -speed
$Sprite.play("Walk")
$Sprite.fliph = true
else:
$Sprite.play("Idle")
velocity.y = velocity.y + gravity
if Input.is_action_just_pressed("Jump") and is_on_floor():
velocity.y = jump
$Sprite.play("Jump")
if not is_on_floor() and velocity.y < -200:
$Sprite.play("Fly")
if not is_on_floor() and velocity.y >= -200 and velocity.y <= 0:
$Sprite.play("Fall")
if not is_on_floor() and velocity.y > 0:
$Sprite.play("Fall1")
if not is_on_floor() and velocity.y > 100:
$Sprite.play("Fall2")
velocity = move_and_slide(velocity,Vector2.UP)
velocity.x = lerp(velocity.x,0,0.2)
func state(state):
match state:
WATER:
physicsprocess(delta)
GAS:
pass
ICE:
pass