There are several ways to approach it. The easiest way is probably, before your enemy doing the chase do distance check. For example
extends RigidBody3D const CHASE_DISTANCE = 10 # Adjust this value as needed func _process(delta): var distance_to_player = position.distance_to(player.position) if distance_to_player < CHASE_DISTANCE: # Add your chasing logic here
Another approach is to use an
Area3Dnode to detect when the player enters a certain area around the enemy. Something along these line:
Create an Area3D Node:
Area3Dnode to your enemy scene. This node will act as the detection zone for your enemy.
Adjust the Shape:
Area3Dnode selected, add
CollisionShape3D, you can adjust the shape and size of the detection zone using the "Shape" property. For example, you can use a
SphereShapeto create a spherical detection zone.
Implement Detection Logic:
Add logic that can handle the detection of the player entering and exiting the detection zone. Here's an example script using GDScript to handle the player detection using an
func _on_area_3d_body_entered(body: Node3D) -> void: if body == player: chasing = true func _on_area_3d_body_exited(body: Node3D) -> void: if body == player: chasing = false func _process(delta): if chasing: # Add your chasing logic here