Hello everyone! I've been playing aroud with Godot a lot for the past few month and I am liking it a lot. However, I am having some difficulties with my current project and I feel it is time for me to seek advice from people with more experience, so here I am :)
First of all, a simplified version of my project:
It's a tilemap, the player spawns on a random tile and you can move within a mesh provided by tiles, nothing special. If you press T, a multiple instances of AI handled parties are added, all they do is roam the map randomly (you can use mouse wheel to zoom in and out for convenience). I am sure many of you will find the code below familiar, this is what I am currenlty using:
func move_along_path(distance : float):
var start_point : = position
#if _target != null:
for _i in range(_path.size()):
var distance_to_next : = start_point.distance_to(_path)
if distance <= distance_to_next and distance >= 0.0 and distance_to_next != 0:
position = start_point.linear_interpolate(_path, distance / distance_to_next)
if _path.size() == 1 and distance >= distance_to_next:
position = _path
distance -= distance_to_next
start_point = _path
There are few issues however:
The more parties I have on the map, the slower it gets, the perfomance is pretty bad. If it was an RTS game or an action, I'd want to be able to handle much bigger numbers of instances at the same time. Is this approch bad for such projects? Is there a better way to handle pathfinding and movement on a map if I don't want unit's path snap to tiles?
I need to add a follow function and I am not sure what would be the best way to do it. You can see 2 commented lines in the code that I was using for this (goto function communicates with nav2d node, gives it new destination and recieves new path) but I think asking for new path every frame is bad for performance. Would it be good enough if I added a 1-2sec cooldown?
The most frustrating for me and basically the reason I am posting all of this since I've spent much time trying to figure it out. If you run the game, press T and spend some time watching the map, all parties will just stop simultaneously for no apparrent reason :( Have I messed something up, am I missing something? Since paths/movement is handled by _process function of each instance separately, I don't really understand why all paths get resetted at the same time, but it looks like they do..
Any useful advice is greatly appreciated!