Search the Community
Showing results for tags 'AStar'.
-
Contrary to the name, I am finding Easystar.js to be intensely not-easy. I have created a tilemap in Tiled with: base, collision, and foreground layers. The collision layer consists of two tiles, a walkable (6669) and a non-walkable(540). I have set up easystar in my create and update loop as described in the docs (see below) but constantly get either "The path to the destination point was not found", or "Your start or end point is outside the scope of your grid.". current code: var level = map.layers[1].data; easystar = new EasyStar.js(); easystar.setGrid(level); easystar.setAcceptableTiles([6669]); easystar.enableDiagonals(); easystar.enableCornerCutting(); easystar.findPath(player.x, player.y, 0, 0, function (path) { console.log("HERE") if (path === null) { console.log("The path to the destination point was not found."); } else { for (var i = 0; i < path.length; i++) { console.log("P: " + i + ", X: " + path.x + ",Y: " + path.y); } } }); I have looked at just about every example, dissected every bit of code I can, and read every doc I can find on the subject matter but cant seem to make any headway. Does anyone have any experience using easystar.js or pathfinding.js?
-
Hello all, I'm having super hard time while trying to implement https://github.com/bgrins/javascript-astar to my testproject @ http://eljuko.com/pathfindingTest/ you can see the js source here http://eljuko.com/pathfindingTest/scripts/main.js I'm getting pretty frustrated with this since it "almost" works but not at all . So please help the stupid to right direction. known issues; - u can't click twice in the same spot. or ofc u can but it wont fire. - sometimes fails to create path - silly waypoints sometimes - grid in -90 degree angle?! EDIT: after few hours of more buttscratching, i kinda start to get to bottom of this. something is not removing the goal node from the closed list when the object reaches its destination. anyone knows this plugin? If anyone knows how to get this working or can provide an algorithm that works; i'll be forever grateful Thanks, eljuko - the stupid
-
While using the AStar.js plugin (from the official Phaser plugin repository), I have been running into a strange bug. Whenever I try to find a path between any two points on my map, the findPath function returns a path of zero length every time. Even more odd, the path, regardless of where I set it to begin or end, always has a start point and goal of (32, 47). This point does exist on my map and is the closest walkable tile to the bottom-right of the map, but there appears to be nothing else of significance about it. It is never mentioned in my code; the number 47 does not even exist in any of my files. The path should not cross that point and a quick manual calculation of A* on my map suggests that (32, 47) would not even be considered, since it should find a direct path to the goal fairly quickly. Does anyone know what might be causing this problem? The only useful tutorial I found online specific to this plugin is the example by Rafarel that is currently a pull request for the Phaser Examples repository. I copied parts of it directly and still had the same bug. If anyone else has a tutorial or example of using this plugin they would like to share, I (and probably quite a few others) would appreciate it, especially if it showed a common use of A* in games, such as pathfinding for multiple characters. Some relevant code: this.AStar = this.game.plugins.add(new Phaser.Plugin.AStar(this));this.AStar.setAStarMap(this.tileMap, 'Tile Layer 1', 'tiles_3_final');this.pathfindKey = this.input.keyboard.addKey(Phaser.Keyboard.ONE);this.pathfindKey.onDown.add(this.pathfindFromCharToChar, this);pathfindFromCharToChar: function() { var path = this.AStar.findPath(new Phaser.Point(40, 18), new Phaser.Point(9, 17)); // var path = ast.findPath(this.player.tilePos, this.otherChar.tilePos); // I tried this and several other ways to get points; // I can confirm that the method of passing the points // in is not part of the problem. this.player.tilePos.x = path.nodes[3].x; // Returns an error, as the path, which should be ~42 nodes long (43 with the start point), // is only 1 node long. this.player.tilePos.y = path.nodes[3].y; this.player.x = tilePos.x*32; this.player.y = tilePos.y*32;},EDIT: After some more digging around in the console, I found some information that might be useful. Forgive me if I ramble on a bit, but I figure that I might as well, since anyone who tries to help either has already gone through the exact same issue and can skip it, or would otherwise have to go through this whole process themselves. The findPath() function is properly passed the correct startPoint (40, 18) and goalPoint (9, 17). However, both start and goal return an AStarNode with an x and y of (32, 47), meaning that something happens in the below segment of code in AStar.js to cause the bug. I can confirm that _tilemap, _layerIndex, goalPoint.y, and goalPoint.x all reference the proper things. Going into properties.astarNode at the correct locations show that the astarNode.x and astarNode,y are set to 32 and 47, respectively. Phaser.Plugin.AStar.prototype.findPath = function(startPoint, goalPoint){ var path = new Phaser.Plugin.AStar.AStarPath(); var start = this._tilemap.layers[this._layerIndex].data[startPoint.y][startPoint.x].properties.astarNode; //:AStarNode; var goal = this._tilemap.layers[this._layerIndex].data[goalPoint.y][goalPoint.x].properties.astarNode path.start = start; path.goal = goal; this._open = []; this._closed = []; this._visited = []; this._open.push(start); ...}While searching for examples originally, I found this Stack Overflow question about AStar.js. I ignored it at the time, but thankfully remembered now. Of course, it remains unanswered, but it did point out that each AStarNode contains the x and y coordinates of the last location to use the same tile as it. So (0, 0), using tile 5, is marked as being at (49, 49), as is everything else that uses tile 5. Likewise, everything using tile 16 is marked as (32, 47). I hadn't noticed since 16 is the only currently used walkable tile, and I didn't think to try using AStar on a non-walkable tile. So the next thing to look at is where the astarNode property is set up on each tile. The updateMap is automatically called when you setup a map for AStar, and can also be manually called after a change to the map. I set up some variables (not shown below) to track whatever the previous tile was so I could check the astarNode property and see if the x and y are changing. Phaser.Plugin.AStar.prototype.updateMap = function(){ var tile; var walkable; //for each tile, add a default AStarNode with x, y and walkable properties according to the tilemap/tileset datas for(var y=0; y < this._tilemap.height; y++) { for(var x=0; x < this._tilemap.width; x++) { tile = this._tilemap.layers[this._layerIndex].data[y][x]; walkable = this._tilemap.tilesets[this._tilesetIndex].tileProperties[tile.index - 1][this._walkablePropName] !== "false" ? true : false; tile.properties.astarNode = new Phaser.Plugin.AStar.AStarNode(x, y, walkable); } }};And apparently, as expected, they are. Going through it line by line, and checking for changes, I can tell that it is line 166 that is changing it. And so the next stop is in the AStarNode constructor, shown below (with comments removed for length). Phaser.Plugin.AStar.AStarNode = function(x, y, isWalkable){ this.x = x; this.y = y; this.g = 0; this.h = 0; this.f = 0; this.parent; this.walkable = isWalkable; this.travelCost;};The console says nothing unexpected happens there (not that I really expected anything to). So I am stuck once again. Somehow, this line of code... tile.properties.astarNode = new Phaser.Plugin.AStar.AStarNode(x, y, walkable);...or a related line is causing other tiles to have their properties changed. All I can think of is that somehow an update to Phaser may have broken this plugin, as it doesn't appear to have been updated since 2.0.4 (at least). I read back through about half of Phaser's entire changelog and cannot see anything that obviously would break this plugin. So that's everything I have found out. Does anyone else who knows more about changes in how Phaser deals with tile properties (or anyone else) know anything that might be causing this problem?
- 3 replies
-
- pathfinding
- AStar
-
(and 3 more)
Tagged with:
-
Hi! I was having a little trouble trying to use AStar + Phaser. I debugged it a bit and discovered a little bug. The X and Y of the astarNode property are wrong, when I set my AStar map, the x and y of all tiles are the same, so the findPath() doesn't work. I'm still trying to fix it, but you guys maybe help me to find the problem faster. Phaser v2.1.1AStar Plugin ( https://github.com/photonstorm/phaser-plugins/blob/master/AStar/AStar.js )tilemap.json ( http://pastebin.com/bQJBxMm7 ) Code:preload: function() { this.game.load.tilemap('map', 'assets/tilemap.json', null, Phaser.Tilemap.TILED_JSON); this.game.load.image('RPGPackSheet', 'assets/sprites/RPGPackSheet.png');},create: function() { this.map = this.game.add.tilemap('map'); this.map.addTilesetImage('RPGPackSheet'); this.layer = this.map.createLayer('LayerName'); this.astar = this.game.plugins.add(Phaser.Plugin.AStar); this.astar.setAStarMap(this.map, 'LayerName', 'RPGPackSheet'); console.log(this.map.layers[0].data[4][6].properties.astarNode);}, The output on the console should be:f: 0,g: 0,h: 0,walkable: false,x: 6, // equals to the second index of layers[0].datay: 4 // equals to the first index of layers[0].data But is giving me in every index the output above:f: 0,g: 0,h: 0,walkable: false, // the walkable changes accordinglyx: 24,y: 13NOTE: It may be related to the height and width of my layer or tilemap ( width: 25, height: 14), but I can't find why its doing that.
-
Hello there! I'm totally new to your forum and it's my first post, here's a quick introduction about me: I'm a French developer who makes games in his free time like Claytus Tower Defense and who works on 360° video web technologies at my job (Kolor). I want to take part on Phaser development and Phaser Plugins development and I want to know how to do it well! I spent the last few days to watch every demo and read the documentation that Phaser provides, it looks to me to be a very good project and a strong knowledgeable team. I haven't found any "How to" or "Good practices guide" about Phaser.Plugin development and submitting. I wanted to start by providing a path finder plugin that works with a Phaser.Tilemap and a JSON file made with the Tiled Software. I ran through some "How the hell can I achieve this the proper way?" kinda questions Maybe you can confirm that I'm right or wrong doing on some points: Need more data from the JSON parser: In the process I needed to adapt the Phaser.TilemapParser.parseTiledJSON because I wanted to have the tileproperties on the layer object from the TiledJSON file. (made in Tiled software) These properties are omitted by the original function so I added this line to my override one: tileProperties: json.tilesets[0].tilepropertiesMaybe there's a better way to achieve this, but I didn't find it. I'd love to pass an additional data {'stringIndex', ... } arguments to game.load.tilemap for example: game.load.tilemap('desert', 'assets/maps/tilemap.json', null, Phaser.Tilemap.TILED_JSON, {'tileproperties'});Adding a debug method: I wanted to output the calculated path by drawing a line on the screen, so on my plugin file, I added a function to the Debug prototype: Phaser.Utils.Debug.prototype.AStar = function(astar, color){ ... Drawing the last calculated path by astar plugin object ...}Here is a screenshot of my work in progress. (debug draw is the red line) I'll upload a live demo a soon as possible with a fun sandbox to test it Many thanks for sharing your work!
-
Hi all, today y manage to make my little AI exercise to work, it's a classical path finding exercise using A* to solve, this is my first JS medium/heavy project and it can be improved A LOT mainly because I did the A star thing myself from scratch which was fun but hard. It needs some cool animations and player control improvements but if you run it and open the console you can see all the steps to solve it when I'm finished it will be on my website but for the time being here is the source code. If any one could check it out and tel me if something could get improved i will appreciate it a lot I have being studding JS and checking other people code and I think I did good practices but I'm not sure. (I'ts SLOW so if you run it it may look like it will crash but hang on and it will solve the puzzle , I think this is because my heuristic isn't the best but i will try different one soon) If someone is interested o could do a tutorial for this so let me know.