+1 vote

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[0])
                    if distance <= distance_to_next and distance >= 0.0:
                        position = start_point.linear_interpolate(path[0], distance / distance_to_next)
                        break
                    distance -= distance_to_next
                    start_point = path[0]
                    path.remove(0)

                if path.size() == 0:
                    #Change state here etc...
                    return
Godot version 3.2.3 stable
in Engine by (15 points)

1 Answer

0 votes

Hi,

I'm guessing here, but maybe it's the loop....
I based my path following on this Kids Can Code example. I don't have loads of enemies on the screen, but I don't see any slow down.

by (1,861 points)

Well that example doesn't use pathfinding at all. It just makes it so a node can travel along a per-determined path.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.