You are on page 1of 1

extends CharacterBody2D

var speed := 150


var jump := 260
const gravity := 500

@onready var anim := $AnimatedSprite2D

func _physics_process(delta):
var direccion = Input.get_axis("ui_left", "ui_right")
velocity.x = direccion * speed

if is_on_floor():
if direccion != 0:
anim.play("walk")
else:
anim.play("idle")

anim.flip_h = direccion < 0 if direccion != 0 else anim.flip_h


else:
if velocity.y < 0:
anim.play("jump")
else:
anim.play("fall")

if direccion != 0:
anim.flip_h = direccion < 0

if is_on_floor() and Input.is_action_just_pressed("ui_accept"):


velocity.y = -jump

velocity.y += gravity * delta


move_and_slide()

You might also like