Hello, I am using the getsimplepath() function with Nav2D and tilemaps so that enemies can search and chase the player. However, since I have a lot of enemies in my project, this causes a massive performance drop (60 fps drops to 6 - 7). How do I improve the performance of this? I've seen people say to only update it periodically, but how do I do this within the physics process since it always updates every frame?
Here's my pathfinding code for reference:
var path = nav_2d.get_simple_path(global_position, player_pos, false)
var start_point = position
var distance = MOVE_SPEED * delta
for i in range(path.size()):
var distance_to_next = start_point.distance_to(path)
if distance <= distance_to_next and distance >= 0.0:
position = start_point.linear_interpolate(path, distance / distance_to_next)
distance -= distance_to_next
start_point = path
if path.size() == 0:
#Change state here etc...