extends CharacterBody2D @onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D var speed = 0.04 var player # Called when the node enters the scene tree for the first time. func _ready() -> void: player = get_node("/root/Game/Witch") pass # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: _chase_witch() pass func _chase_witch() -> void: var direction = Vector2(player.global_position - global_position) velocity = direction * speed velocity = direction * speed if direction == Vector2.ZERO: animated_sprite_2d.play("idle") elif abs(direction.x) >= abs(direction.y): if direction.x < 0: animated_sprite_2d.play("walk_left") else: animated_sprite_2d.play("walk_right") else: if direction.y < 0: animated_sprite_2d.play("walk_up") else: animated_sprite_2d.play("walk_down") move_and_slide()