How do I update random paths for more enemies (pathfinding)

Get help using Construct 2

Post » Sat Mar 07, 2015 4:43 pm

hey guys, i'm still working on my game and there's a problem that i can't think of how to do..

so i spawn at some time intervals enemies that need to traverse downwards and avoid obstacles (using pathfinding ofc.)

my screen/layout size is 1366x768 pix. now i have set properly spawning points for every sprite, added them bullet behaviour, DooL, and solid (obstacles), gave them
angle 90 and speed 20. so my obstacles move at speed 20 downwards, which seems like you're traveling upwards, but now i spawn on the upper side enemies (with pathfinding) - example: create object enemy1 on (800,0). then i call find path (random(0,1366), 768) and on pathfound - move along path.

so what's the problem here? once my enemy starts moving it goes through my obstacles, but avoids them on the place they were before in time.
hacking that up, i've come up with idea to set "if on screen + every 0.5 sec" - regenerate obstacle map + move along path. - noticed that i need to use
find path (with new obstacle map) to find a new path for that enemy. problem is that this enemy now will gain different random position every 0.5 sec which i don't want.

so how can i create a function that updates general obstacle map (same cell size for every enemy) and find path for each enemy on screen to where it randomly got assigned when created, each 0.5 sec?

uhh.. i kinda feel like i could have simplified this.. anyway thnx for helping!
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
42
S
14
G
12
Posts: 624
Reputation: 9,421

Post » Sat Mar 07, 2015 8:42 pm

If you can re-work it so the walls don't move and you just change the scroll position then you won't need to update the obstacle map.
B
92
S
32
G
107
Posts: 5,273
Reputation: 69,957

Post » Sat Mar 07, 2015 10:27 pm

well it's a bit tough to make walls on sea :D :)

anyway i've got it working somehow, i update obstacle grid every 0.2 sec and then foreach instance of enemies find path and move them along path when found

anyway it works good and idon't have more then 10 enemies max on screen. i haven't lost a single FPS and it seems to work correctly.. for now.
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
42
S
14
G
12
Posts: 624
Reputation: 9,421


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 18 guests