I'm trying to make a zombie game. I got everything worked out except for how to make the zombies set themselves as obstacles. So zombies will avoid other zombies and walk around eachother to reach the player. I tried using regenerate obstacle map but it makes the game skip really bad.
Any advice or suggestions on how to go about this is appreciated.
This may sound dumb, but have you tried giving your zombies the solid behavior? Though it will most likely cause a lot more calculating as the zombies will constantly be recalculating their path based on which zombies get in their way...
Yeah, I thought that should work too. But the zombies just act like I never made them Solid and I see no change at all. But they seem to be avoiding all other objects with the Solid behavior, just not their fellow zombies. I can't seem to understand if this is because the zombies are Moving Objects, or if because they are the Same Object...
You can investigate if it is because they are the same object quite easily. Create a new zombie and copy the old zombies behaviors and see if the new and the old avoid each other.
Let me know what you find out, I have a problem close to yours and never figured out how to solve it.
Develop games in your browser. Powerful, performant & highly capable.
You shouldn't do this; if you read the manual entry on Pathfinding you'll see that it is extremely CPU intensive to change the obstacle map, so you definitely can't do it on a regular basis.
Ashley: do you then have any ideas for a solution?
I assume that if the number of zombies and the terrain is simple(cell size large), then it is possible to recalculate the path fairly often without slowing down the game to much.
I played with the pathfinding of multiple instances when i used MMF. Its very tricky to avoid lag.
You need to devise a system that deliberately slows down the pathfinding calculations.
Lets say you have 30 zombies. You do not want your cpu trying to calculate 30 paths in fast loops constantly. You need to figure out how much processing power you think you can get away with pathfinding taking up and design it so that it ONLY uses that amount of processing regardless of the number of zombies. Adding more and more zombies would essentially make them more stupid and slower to make their mind up, but you know the fps would be constant.
Yeah. I guess there is no easy way to do it then.. My only idea so far is manually setting up a system where a Zombie Stops Pathfinding when it collides with another Zombie that has a Closer Distance to the player, and manually make the Stopped Zombie find a way around the Zombie it Collided With before resuming Pathfinding to the player.
This seems like its gonna be really hard and buggy, but it's all I got so far. Any other ideas would be great. Thanks for the responses and help though.
Maybe just offset them from each other each frame when collisions happen.
The only foreseeable problem would be if there is a wall of zombies; the zombies at the rear won't be able to path around; but hey, zombies are stupid!! ;)
Perhaps they could also forget pathfinding for a moment swipe at the zombie that is in their way, then resume pathfinding when the blocking zombie is gone :P
I found a small and very simple solution if anyone is interested.
On my "On Pathfinding Path found" event, I added a subevent that checks if the Zombie is currently overlapping another Zombie. It checks which Zombie is the closest and which is the farthest. It then assumes the Farthest Zombie is behind the Closest Zombie and Stops its Pathfinding. It then moves the Closest Zombie along the path, assuming its also not colliding with another Zombie that is even Closer.
It's not too buggy and is better then nothing for now.
When i was working on a zombie game I ended up ditching precision pathfinding and instead gave them a decent Line of Sight system and ability to detect closest targets and a few other useful things.
They recorded the most recent location they spotted a target and would go to that location. If they lost sight of the target they still knew the last place they saw them and would go there, that often meant they regained sight and could change direction. if they were quick enough it meant they would end up following targets round corners even if they lost line of sight for several seconds. They had a timer. When they spotted something it sent an 'alertness' value right up and for every second they lost sight it reduced. When it dropped below a threshold they gave up and returned to wondering about.
Pathfinding is a strategic operation - it certainly shouldn't be recalculated on every step of an update loop, and preferably much, much less than that. Nor should it necessarily be calculated for every instance in the game. Some alternatives: