extends CharacterBody2D
var chase = false
var speed = 100
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
var player = $"../../player/player1"
var direction = (player.position - self.position).normalaized
if chase == true:
velocity.x =direction.x
move_and_slide()
func _on_detector_body_entered(body: Node2D) -> void:
if body.name == "player"
chase = true
* List item
I wrote some code for a mob to attack the player when he enters its area of ​​effect, but the code doesn’t work.