I'm making a 2D zombie game. The zombies are wandering randomly usually, but when the player is nearby, they will chase him. The problem is that, having more than 5-6 zombies at a time makes my game freeze sometimes for about 10 seconds. During this time, physics_process skyrockets and the game even becomes Not Responding at times. The zombies are performing path recalculations about once every 0.3 seconds. Is that a lot? What are some other potential fixes for these freezes?
#My game freezes for around 10 seconds
9 messages · Page 1 of 1 (latest)
This is the physics_process and navigate functions of the zombies. These seem to be causing the freezes
Is there a better implementation ? Or maybe some other way?
Here are the monitors just in the middle of a freeze
There were 7 zombies spawned during this freeze
And it actually ended up in a crash
Solved. I deleted the navigation mesh made by the huge tilemap and made it by hand with a navigationregion2d
The TileMap build-in navigation is very inefficient. I assume everytime you changed a cell with navigation of your TileMap your game freezed. This is because the TileMap changes the navigation map and the map syncs on the next physics frame. The sync of a very large TileMap takes forever due to the inefficient amount of navigation mesh edges that come with each single cell. In godot 4.2 you can try to bake a navigation mesh for your TileMap with a NavigationRegion2D. You can disable the Tilemap navigation in this version so it does not get created and you can use the NavigationRegion2D instead.