Lucas Posted February 20, 2014 Share Posted February 20, 2014 How do the character's movement using pathfinding? var tween; function create(){ game.input.onDown.add(moveSprite, this);} function moveSprite (pointer) { if (tween && tween.isRunning) { tween.stop(); } var duration = (game.physics.distanceToPointer(localPlayer.sprite, pointer) / 200) * 1000; tween = game.add.tween(localPlayer.sprite).to({ x: pointer.x, y: pointer.y }, duration, Phaser.Easing.Linear.None, true);} Example: Link to comment Share on other sites More sharing options...
XekeDeath Posted February 20, 2014 Share Posted February 20, 2014 Use an A* library to generate the path, and tween the position of the sprite to the waypoints that it generates. Link to comment Share on other sites More sharing options...
Lucas Posted February 20, 2014 Author Share Posted February 20, 2014 and how to get the coordinates that are collision? U can pass me the link of this A* library? And examples, pls.. Link to comment Share on other sites More sharing options...
XekeDeath Posted February 21, 2014 Share Posted February 21, 2014 AStar: https://github.com/bgrins/javascript-astarSample usage is on the page.If by "coordinates that are collision" you mean walls to walk around, you define that in the grid you pass to the A* with a 0. Link to comment Share on other sites More sharing options...
Lucas Posted February 21, 2014 Author Share Posted February 21, 2014 I wanted it to be like the blue line, and not as green. I tried with this plugin for phaser, editing to function as the blue line? I tried using the function astar.disableDiagonals(); and astar.enableDiagonals();..but did not work. Link to comment Share on other sites More sharing options...
XekeDeath Posted February 21, 2014 Share Posted February 21, 2014 When you call the astar.search function, that is where you tell it to not use diagonals.search: function(grid, start, end, diagonal, heuristic)All you need is the first 3 and it should work for you. It does for me. Link to comment Share on other sites More sharing options...
Lucas Posted February 25, 2014 Author Share Posted February 25, 2014 But i have this error in console log of chrome: Uncaught TypeError: Object [object Object] has no method 'tileset' my game: game.load.tileset('img1', 'resources/1.png', 32, 32);My phaser version is the latest.. Link to comment Share on other sites More sharing options...
XekeDeath Posted February 26, 2014 Share Posted February 26, 2014 That is a completely different problem.That is telling you that the tileset function you are trying to call does not exist.If you are loading a sprite sheet to use as a tileset, you probably wantgame.load.spritesheet('img1', 'resources/1.png', 32, 32); Link to comment Share on other sites More sharing options...
Lucas Posted February 27, 2014 Author Share Posted February 27, 2014 Finally, support for the new version: https://github.com/appsbu-de/phaser_plugin_pathfindingthx ######## Now my avatar is teleporting map.How can I make it move following the correct coordinates?function findPathTo(tilex, tiley) { pathfinder.setCallbackFunction(function(path) { path = path || []; for(var i = 0, ilen = path.length; i < ilen; i++) { localPlayer.sprite.x = path[i].x*32; localPlayer.sprite.y = path[i].y*32; } blocked = false; }); pathfinder.preparePathCalculation([0,0], [tilex,tiley]); pathfinder.calculatePath();}The lace (for) is making it run several times, hence teleportation. ###################### II did so:function findPathTo(tilex, tiley) { pathfinder.setCallbackFunction(function(path) { path = path || []; var i = 0; var interval = setInterval(function () { if(i == path.length-1){ clearInterval(interval); blocked = false; } localPlayer.sprite.x = path[i].x*32; localPlayer.sprite.y = path[i].y*32; ++i; }, speed/6); }); pathfinder.preparePathCalculation([0,0], [tilex,tiley]); pathfinder.calculatePath();}And worked! Thx! Link to comment Share on other sites More sharing options...
SMWarren Posted March 31, 2014 Share Posted March 31, 2014 Everytime I try to implement this script in my phaser application it freezes. Can anyone show an example of how to make an ai character find you in a tile map like in the example, star struck, http://examples.phaser.io/_site/view_full.html?d=games&f=starstruck.js&t=starstruck. AndreasWienes 1 Link to comment Share on other sites More sharing options...
Recommended Posts