Performance issues with get_simple_path

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Jeff3301

My project is a 2d topdown game with a lot of enemies, and my move function that uses get_simple_path 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

This function is running on _physics_proccess(delta)

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

rakkarage | 2020-07-13 03:34

:bust_in_silhouette: Reply From: brainbug

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