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

0 favourites
  • 3 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • 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!

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • well it's a bit tough to make walls on sea

    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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)