Godot Version
4.5.1
Question
Hello everyone!
I have a problem I can’t seem to solve: I have characters that follow the player. When they get too close together around the player, some are pushed out of the navmesh. As a result, the characters can no longer move. I use the “avoidance” system on my characters’ NavigationAgent2D to prevent them from stepping on each other.
Here is the navmesh:
The settings:
And this is when the characters surround the player and how some of them end up outside the navmesh.
If anyone has any ideas on how to avoid this “push” effect outside of the navmesh, that would be great. Thanks in advance.
PS: Here’s the code that allows my characters to move
func _ready() -> void:
add_to_group("enemies")
if fov:
fov.seen.connect(_on_character_detected)
if navigation_agent and navigation_agent.avoidance_enabled:
navigation_agent.velocity_computed.connect(_on_safe_velocity)
navigation_agent.max_speed = chase_speed
func _on_safe_velocity(safe_velocity: Vector2) -> void:
position += safe_velocity * get_physics_process_delta_time()
set_direction()
func move(speed: float, _delta: float) -> void:
if navigation_agent.is_navigation_finished():
return
var next_path_position: Vector2 = navigation_agent.get_next_path_position()
var new_velocity = global_position.direction_to(next_path_position) * speed
if new_velocity.length() < 1.5:
navigation_agent.velocity = Vector2.ZERO
return
if navigation_agent.avoidance_enabled:
navigation_agent.velocity = new_velocity
else:
_on_safe_velocity(new_velocity)




