pls help
this is the script of my guest in my game is supossed to chase player and when he's close, catch him but is not working the raycast detect the player but the guest is no moving??
class_name GuestBase extends CharacterBody2D
enum STATE {
IDLE,
CHASE,
RUSH,
STUN
}
var current_state = STATE.IDLE
var rush_cooldown: bool = false
#var player: CharacterBody2D = null
var can_detect = false
u/export var speed: float
u/export var chase_speed: float = 20
u/onready var _collision: AudioStreamPlayer2D = $PineappleCollision
u/onready var _anim = $AnimationPlayer
u/onready var _nav = $NavigationAgent2D
u/onready var player = $Player
func _ready():
if $Sprite2D.material:
$Sprite2D.material = $Sprite2D.material.duplicate()
rotation\_degrees = randi\_range(0,360)
await get\_tree().create\_timer(0.1).timeout
can\_detect = true
add\_to\_group("guest")
func _physics_process(delta: float) -> void:
match current\_state:
STATE.IDLE:
velocity = [Vector2.ZERO](http://Vector2.ZERO)
\_on\_idle()
STATE.CHASE:
if !player:
current_state = STATE.IDLE
return
var direction = (player.global\_position - global\_position).normalized()
velocity = direction \* chase\_speed
look\_at(player.global\_position)
move\_and\_slide()
\#if $NavigationAgent2D:
#var direction = to_local(_nav.get_next_path_position()).normalized()
#velocity = direction * chase_speed
#look_at(player.global_position)
#move_and_slide()
STATE.RUSH:
if !is\_instance\_valid(player):
current_state = STATE.IDLE
_anim.play("idle")
return
var direction = (player.global\_position - global\_position).normalized()
\_anim.play("rush")
\#await \_anim.animation\_finished
velocity = direction \* chase\_speed \* 2
look\_at(player.global\_position)
move\_and\_slide()
rush\_cooldown = true
current\_state = [STATE.CHASE](http://STATE.CHASE)
await get\_tree().create\_timer(2.0).timeout
rush\_cooldown = false
\#if global\_position.distance\_to(player.global\_position) < 15:
#Events.player_caught.emit()
#print("u loose")
STATE.STUN:
velocity = [Vector2.ZERO](http://Vector2.ZERO)
\_anim.play("idle")
func _on_recalculate_route_timeout() -> void:
if player:
\_nav.target\_position = player.global\_position
func _on_idle() -> void:
pass
func take_damage(damage: float) -> void:
current\_state = STATE.STUN
Util.audio\_play\_varied\_pitch\_2d(\_collision)
$hitflash.play("hit")
await get\_tree().create\_timer(3.0).timeout
current\_state = STATE.IDLE
if player:
current\_state = [STATE.CHASE](http://STATE.CHASE)
var _things_on_my_field_of_view: Dictionary[Node2D, RayCast2D]
var _ray: RayCast2D
func _on_field_ofview_body_entered(body: Node2D) -> void:
\_ray = RayCast2D.new()
\_things\_on\_my\_field\_of\_view\[body\] = \_ray
add\_child(\_ray)
func _on_field_ofview_body_exited(body: Node2D) -> void:
\_things\_on\_my\_field\_of\_view\[body\].queue\_free()
\_things\_on\_my\_field\_of\_view.erase(body)
func _process(delta: float) -> void:
\#global\_position = player.global\_position
for thing in \_things\_on\_my\_field\_of\_view:
\_ray = \_things\_on\_my\_field\_of\_view\[thing\]
if \_ray.get\_collider() == thing:
current\_state = [STATE.CHASE](http://STATE.CHASE)
else:
pass
\_ray.target\_position = (thing.global\_position - global\_position).rotated(-rotation)
\_ray.force\_raycast\_update()
move\_and\_slide()