Hello, I just started making a 2D top down stealth game. Most of the levels will be in buildings, with walls and rooms.
Right now my enemy has a few states, idle, chasing, etc. I have coded out what I want the enemy to do upon seeing the enemy, when chasing the enemy and stuff. I am using NavMeshPlus for 2D pathfinding.
My problem lies in what happens if the enemy lose sight of me (the player). What I want them to do is to start an organized search to go through every part of the map to look for me.
Is there a best way to do this?
My idea now is to maintain a grid as a graph (nodes are squares with trigger colliders…?) on the map. Each enemy will then perform a Breadth-First-Search from their point on the graph to find the closest point that is “not searched” yet, and set a path there. Upon touching any node on the graph, that node will be set as “searched”.
My concern is that this may not be efficient? My game won’t be that big however, my game should only have 60 bots maximum, and the maximum number of nodes at a reasonable size should be 40 x 40 = 1600 nodes for each level. (this is an generous upon bound).
A potential optimization would be to do direct distance comparing if the number of nodes not searched yet is small and BFS might meet a lot of searched nodes already. Another way is maybe to do depth first search to find a reasonably far point so that the path is not updated too often.
The reason I decided on this is because each Bot should search a different place
Another way would be to manually place different points on the map that has to be searched (example, rooms), that way I would be sure that the number of points remain small.
However my main concern is because one of the end goals for the game is to make a level editor as well, where players can design their own levels to share and play. I wouldn’t want the level editor to include placing your own points on the map for the bots to search, so it should have the same “implementation” for all maps.
Thank you for reading this long post. This is my first time making a game and I really intend to finish it. I apologize if I made some rookie mistakes in game design. Right now I am targetting it for PC, but I hope that it could be ported to mobile as well next time.