I am trying to find the closest thing around my NPC, for now, they check it every physics frame to make sure it still there or another NPC has took it. The things they try to find are only on layer 4 and the ShapeCast3D has it’s maks on layer 4.
When the NPC get close to multiple things they start shaking and move erratically because they try to go to a different thing in the ShapeCast3D instead of the nearest.
I tried to fix that by making it check the distance to the things with the following code, but it still doesn’t work.
if task_searcher.is_colliding():
var hit = task_searcher.get_collider(0)
for i in range(task_searcher.get_collision_count()):
if global_position.distance_to(task_searcher.get_collision_point(i)):
hit = task_searcher.get_collider(i)
I did also try to change the Max Results and Margin values but no luck.
Help pls?