4.2.1
how should I add my animations to this script for my 2d game?
extends CharacterBody2D
@export var speed: float = 100.0
# Hearts UI node
@onready var hearts_ui = $HeartsUI
# Health
var heart: int = 3
func death():
if heart <= 0:
get_tree().reload_current_scene()
death()
func take_damage():
heart -= 1
if heart < 0:
heart = 0 # safety so it doesn't go negative
func _physics_process(delta: float) -> void:
var input_direction = Vector2.ZERO
if Input.is_action_pressed("ui_right"):
input_direction.x += 1
if Input.is_action_pressed("ui_left"):
input_direction.x -= 1
if Input.is_action_pressed("ui_down"):
input_direction.y += 1
if Input.is_action_pressed("ui_up"):
input_direction.y -= 1
if input_direction.length() > 0:
input_direction = input_direction.normalized()
velocity = input_direction * speed
move_and_slide()