A question about pathfinding.

0 favourites
  • 7 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • So, in my game I use pathFinding to control my character.

    Now, I want to make one layout with infinite scroll.

    My problem is that pathFinding cannot move outside of the layout, and basically the layout size doesn't play a role here, since I'm using unbound scrolling and just move sections from left to right or right to left as they leave the viewport.

    Is there any way to get around pathfinding outside the layout bounds?

    A few other solution that I thought of were to:

    1. Make a really really really big layout and hope no one walks that far in circles :)

    2. Use a different move behavior or keep the player centered and scroll the scene around him, though those will open some cans of worms with a bunch of logic I already have setup around the pathfinding. Which I'm hoping to avoid.

    Anyone has another idea?

    Tagged:

  • Ashley Do you think an action to set the pathfinding cell area bounds is something feasible, should I bother with posting it as a suggestion?

    I understand that the bounding was added to avoid infinite memory usage.

    But in my case I really don't need more than 600px, I just need to be able to move it around.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Solution 1 isn't great because on big maps the Pathfinding behavior will be quite slow.

    If your game is grid-based, you can try EasyStarJS behavior, it's much faster. But still will probably struggle if your map is 100000x100000 tiles in size.

    One workaround is to use an invisible tilemap, which you center on the player position and mark all obstacles on it. Then use EasyStarJS to find the path.

  • Thanks for the answer, I appreciate your input.

    I figured there is a limit and I would have stress test that but yeah, it's not an optimal solution.

    Though basically the whole layout area is 1920px (6 sections of 320 that loop). The area is just a round corridor with doors, so I don't imagine anyone walking in circles more than 2-3 times, but I would probably want to have 10 loops just to be sure. Hopefully pathfinding can handle 20,000px.

    If I really have no choice I thought of maybe breaking the 3rd wall as an option, "hey you reached the end of the world, please turn back" or something like that :)

    As for EasyStarJS, I prefer not use 3rd party addons, as I've been burned before with unmaintained and broken addons.

    P.S I'm already using an invisible tilemap to set the blocked cells, I didn't intend on centering it on the player, as I would probably need to regenerate the map every tick, I just have a tilemap for each section, and when I push that section to the other side, I regenerate the area around it.

  • I get that you’re using unbounded scrolling but if the map is fixed you could just put the whole thing within the layout bounds.

    Since you’re doing it for control you could replicate obstacles on screen to the layout bounds, do pathfinding there and just move the player from that. You just have to deal with the offset from the screen to the layout bounds. Bear in mind pathfinding will be done with only partial knowledge of the map. Guess this is similar to shifting things around to make the on screen stuff be on the layout.

    Third option could be rolling your own pathfinder. The pro of that is more control. The con is more work to make it match what the behavior does.

    One idea could be using Dijkstra's algorithm from the player’s position to the target. Instead of a 2d array of the cells you could do a sparse array with xy pairs as keys for cells. Or you could use astar. The idea is we have more options for how we define the graph of walkable nodes. The behavior uses a 2d grid of cells within the layout bounds. What i mentioned above is a sparse 2d grid of cells with no bounds. Beyond that there’s navmeshes or similar stuff.

    If your obstacles are mostly convex then you can get decent pathfinding with raycasts and wall following.

    Kinda just throwing a bunch of ideas out there.

  • Oh wow, that's interesting, I haven't thought about that.

    So let me see if I got it right.

    The pathfind grid will be fixed within the layout and off screen and the actual scene will be outside the layout.

    The player image sprite will get the X/Y position based on the current section is at + the pathfind object X/Y offset?

    I guess that means when the pathfinding object reaches the right edge I need to move it back to X = 0, then he should continue walking from there with a new path based on the remaining distance from the mouse click X/Y spot.

    I wonder if that'll work seamlessly, without stopping the movement mid walk.

    I don't think I'll be venturing into making my own pathfinder, at least not at the moment. But that sure is an option.

  • Basically that. I’d have it replicate what’s on screen though. Or just a layout sized area centered on the screen.

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