I have a chase script for my enemy,
kinematicbody2d, to chase the player and im using nav2d for its navigation, every time it calls the
get_simple_path method the game lags for a bit and with more enemies it gets worse. I check to see if my script cause any lag by just setting a single path to follow and it went smoothly. When i check the
get_simple_path it lagged even though im not using the variable i used to store it in.
Here is the chase script
onready var player = get_node("../Player")
onready var nav2d = get_node("../Navigation2D")
# if the path has more than one point
if points.size() > 0:
var distance = get_global_position().distance_to(points)
var direction = points - get_global_position() # direction of movement
if distance > 5:
movement(Vector2.ZERO, 0) # close enough - stop moving
here is how i get my path, i set it on a timer cause just placing it in
_process caused to much lag.
points = nav2d.get_simple_path(global_position, player.global_position)
I dont know what is wrong cause when I try my script it in a new project it runs fine until there are too many enemies loaded in.
Im using a nav polygon for my path.
if any extra info is need please ask.