Problems with enemy programming [DOOM LIKE game]

Godot Version

Godot 4

Question

Hi

I’m starting in development and games with Godot 4.
I found a really cool tutorial by Marcial Lincoln about a clone of Wolfenstein 3D, but I’ve been having difficulties because the tutorial was made in version 3.5 and I’m reproducing it in version 4. I managed to resolve several bugs that arose during development, but there are two things I couldn’t resolve.

1- An identification/declaration error;
2- Some tiggers that were made with “yield” and I can’t make them work with “await”

Can anyone give me a light?

I’ll leave the enemy code where I find these problems to better illustrate

extends CharacterBody3D


enum StateMachine{ IDLE, WALK, SHOOT, DEATH }
@export var health := 15
@export var speed := 7
@export var distance_follow := 20
@export var distance_shoot := 10

var state = StateMachine.IDLE
var motiom = Vector3()
var death := false
var shooting := false
var target = null


@onready var animated_sprite = $animated_sprite
@onready var ray_cast = $ray_cast
@onready var collision = $collision
@onready var hit = $hit


#@onready var player : CharacterBody3D = get_tree().get_first_node_in_group(world)



func _ready():
pass

func _physics_process(_delta):
#motion = Vector3

match state:
StateMachine.IDLE:
animated_sprite.play("idle")

if _get_distance_player() <= distance_follow:
state = StateMachine.WALK

StateMachine.WALK:
animated_sprite.play("walk")
velocity = ray_cast.cast_to.normalized() * speed

if _get_distance_player() <= distance_shoot:
state = StateMachine.SHOOT

if _get_distance_player() > distance_follow:
state = StateMachine.IDLE

StateMachine.SHOOT:
if not shooting:
_shoot()

if _get_distance_player() > distance_shoot:
state = StateMachine.WALK

StateMachine.DEATH:
if not death:
death = true
animated_sprite.play("death")
collision.disabled = true


move_and_slide()


func _get_distance_player() -> float:
ray_cast.cast_to = to_local(target.translation)
if ray_cast.is_colliding():
var body = ray_cast.get_collider()
if body == target:
return translation.distance_to(target.translation)

return INF

func _shoot() -> void:
shooting = true
animated_sprite.play("shoot")

await animated_sprite.animation_finished
animated_sprite.play("idle")
shooting = false


func apply_damage(damage:int) -> void:
health -+ damage
if health<=0:
state = StateMachine.DEATH



hit.show()
await get_tree().create_timer(0.1).timeout
hit.hide()

Does anyone know what I’m doing wrong?

Where line the errors is happening and what is the error debugger shows?