[BEHAVIOR] EasyStar.js pathfinding for tilemap

2 favourites
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Hi ! I recently stumbled upon this neat little API for pathfinding and thought it would be cool to wrap it up inside a plugin/behavior for C2. I thought a behavior extending the official tilemap made the most sense for this so here goes :

    live example (Drag and drop the blue/green square, and right-click to add/remove obstacle.)

    example capx

    behavior files

    easystar demo done in C2 (need moveTo behavior)

    live version

    The behavior is rather straightforward, just hook it up to a tilemap, define walkables tiles with the appropriate actions and you're set. It uses a tag system so you can make multiple find path calls simultaneously, and EasyStar.js allows for asynchronous calculation if need be. Just try it out !

    edit: corrected links, added another demo

    Behavior files v1.01

    v1.01 has an updated core (now using EasyStar.js 0.2.3, slightly modified to accommodate C2)

    Key features are an optimized algorithm, possibility to add specific costs at tile coordinates, option to enable/disable corner cutting when moving diagonally

    Behavior files v1.02

    Yet another update to the core, now using EasyStar.js v0.4.1. Now featuring directional conditions and an even more optimized algorithm.

    Behavior files v1.03

    Small update to correct a bug with the "SetTileAt" override. Also added a condition to test if a tile is walkable and an expression to get the cost from a particular tile.

    **New**

    Behavior files v1.04

    C3 version - automatic conversion (seems to work perfectly but use at own risk)

    I stumbled upon a nasty bug that made the plugin rebuild its array representation of the tilemap every tick instead of only on the first tick. This could have caused quite a bit of slowdown when working with large tilemaps.

    Added a new condition : "Is tile walkable from". Basically the same as "Is tile walkable" but this one take into consideration directional conditions and thus need another coordinates pair. It will always return false if the two pairs of coordinates aren't neighbours.

    Also removed the jQuery dependency by removing the jquery.map() call and using array.map() instead. All modern browsers should now support this.

  • This looks like a really nice extension to tile map, thanks for your efforts…but all your links lead to the demo.

  • Thats not a bad idea, tilemap with efficient pathfinding.

    Will try it out.

  • Bummer, I used the web version of Dropbox and it seems it didn't correctly "copy to clipboard" those links. I'll correct them immediately.

  • Wow, you have it running every tick, and its got no lag.

  • It's indeed pretty fast. At first I did the "every tick" part just as a quick way to test the plugin... but then I saw how it did not even lower the fps one bit, so I kept it !

    However, it's still not a good idea to do pathfinding on an "every tick" event, mind you !

  • This is a really great behaviour, thanks again.

  • What is really amazing to me is that it ran so smooth on my phone. : D

  • Its breaking nw.js with minification.

  • Thanks for sharing!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Its breaking nw.js with minification.

    Probably has something to do with the fact that I used an external JS file. I'll investigate further when I get the chance to !

  • Ok thanks!

    This plugs perfect for what Im trying.

  • According to this, I'd have to create an extern definition file and supply it to the command line when calling the minifying module. However, we have no control on how the module is called, so I guess it's tough luck for minifying when using an external library. However, you could probably incorporate the JS file of the library inside the runtime.js and remove the dependency inside the edittime.js, and hopefully let the closure compiler do its magic withtout breaking anything...

  • How do you do that before it gets compiled?

    I mean the runtime gets created and then minified in basically the same step.

  • Oh, I meant the runtime and edittime of the behavior. There's an external file called easystar-0.1.13.js, I think that by copying all its content over to the runtime.js of the behavior, it should allow the minification to perform without breaking anything. The "dependency" inside the plugin setting (edittime.js) should also be removed.

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