Pathfind with Moving Obstacles

Get help using Construct 2

Post » Wed Feb 27, 2013 8:30 am

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.
Thanks.
B
6
S
1
Posts: 31
Reputation: 1,237

Post » Wed Feb 27, 2013 9:16 am

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...
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,428

Post » Wed Feb 27, 2013 9:33 am

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...
B
6
S
1
Posts: 31
Reputation: 1,237

Post » Wed Feb 27, 2013 10:11 am

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.
B
5
Posts: 15
Reputation: 957

Post » Wed Feb 27, 2013 2:39 pm

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Wed Feb 27, 2013 9:58 pm

@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.
B
5
Posts: 15
Reputation: 957

Post » Wed Feb 27, 2013 10:18 pm

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.
B
14
S
4
G
3
Posts: 38
Reputation: 3,741

Post » Wed Feb 27, 2013 11:36 pm

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.
B
6
S
1
Posts: 31
Reputation: 1,237

Post » Wed Feb 27, 2013 11:57 pm

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
B
11
S
2
G
3
Posts: 22
Reputation: 2,595

Post » Thu Feb 28, 2013 12:25 am

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.
B
6
S
1
Posts: 31
Reputation: 1,237

Next

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go and 20 guests