Hi. I'm projecting a builder game of sorts, and I'm having doubts on the core pathfinding function. Lemme explain:
I have an environment defined by an array with two Z levels. The first one is for tiles (1 or 0), the other one is for entities (by ID).
The environment is defined by either 4x4 rooms, 2x4 corridors, or 3x3 corners. All connections are on a grid.
I want an entity to first scan for points where it wants to go and then plot possible paths to said destinations. Once it has done that, decide for the shortest path (eg, "I'm at 3,5, there's a point at 10,6 and another one at 6,10, which one is the shortest accounting for the shape of the playing field?).
The pathfinding function included in construct2 is not really cutting it for me, because it moves the sprite along a grid. What I want is to run it for every possible destination, and return a length in tiles *before* moving it, as the game will be rendering every .3 seconds and I need the entities to move one tile every time the game renders. I would also need to be able to stop it and re-run it if the path became obstructed while the entity is on the move.
Really filthy casual developer here, so any pointers would be appreciated.
Thanks.
It sounds like you need "pathfinding", but do not want the stock "path following" behavior. I am in the same boat.
I first looked at implementing A* purely in events. There are lots of good tutorials on this, just google "a star pathfinding". I was about ready to start coding it into events when I ran across Magistross excellent "easystar" plugin designed for tilemaps.
All you have to do is put in a tilemap and it will quickly determine paths in realtime. You can even optimize it for compute time vs accuracy. In my case, I was looking to find not necessarily the absolute shortest path, but one that minimizes CPU load because I have lots of 3D physics going on already in the game.
I am working in Q3D, so I have to implement my own movement system. Easystar is perfect for this.
Here is a demo:
https://www.scirra.com/forum/behavior-easystar-js-pathfinding-for-tilemap_t129056?&hilit=easystar