Low FPS

Hi everyone! It looks like Pathfinding eats up a lot of memory, I have such a problem, when the game is just running, I have an average FPS of 170, each unit is unique and has a different walking distance, units that can go 3 fields forward do not reduce FPS much, it does not fall below 100 , and their movement looks smooth, but units that have a distance of 6 cells, when they move, the FPS drops to 50-60, and freezes occur … any tips on how to optimize this? Second question, does the overall grid size affect this? I have a whole grid of 100 by 100, but it seems to me that this should not affect because only the unit’s distance range is used in the calculations

Remember that each extra unit of move distance increases the number of paths that need to be tested by a not insignificant factor… not to mention the number of squares each path will have to consider…
For example:
A movement of 2 means that roughly a 5x5 square will need to have paths tested, about 24 calls to the pathfinder…
A movement of 3 brings that up to 7x7, or 48 calls (you don’t need to test the cell you’re standing on).
A movement of 4 is 9x9 or 80 calls…
A movement of 6 is a 13x13 area which is 169 paths to check.

The pathfinding version that is included in the course is not a highly optimized pre-baked pathfinding system (like say, the navmesh which is great on open terrain, but not so great on tiles). There are several solutions like the A* Project that will do a much better job.

I was hoping that it might be possible to reduce the load a little if I made changes in the code, but it seems not. Now I installed the A * Project package for myself, I’ll try to figure it out. Thanks for the answer

The main change you can do is stop refreshing the path whenever a Unit moves position, instead only calculate the path when the Unit reaches the end point.
That will solve the stuttering as the unit is moving and it will feel much smoother.

1 Like

Privacy & Terms