0 votes

My project is a 2d topdown game with a lot of enemies, and my move function that uses getsimplepath and tile navigation is consuming a lot of performance.

Here is my code:

var point = 0

func move():
    target = navigation.get_simple_path(global_position,GameManager.playerNode.global_position,false)
    if global_position == target[point]:
        point += 1
    motion = (target[point] - position).normalized() * moveSpeed
    move_and_slide(motion)
    pass

This function is running on physicsproccess(delta)

in Engine by (14 points)

ya try not to do it each time/frame... only when path needs to change. if click or input or etc

1 Answer

0 votes

pathfinding is generally expensive.

Don't recalculate the path every frame, do it once per second or only if the player
had moved a certain distance

by (282 points)
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.