A flexible 3D node based A* pathfinding system
For a simpler to use 2D grid based system, have a look at gamvas.AStarGrid
new gamvas.AStarMap(withFirst);
withFirst | include the first element of a path when searching (optional, default: true) Example: |
Create a new path finding system and add two nodes that are connected to each other.
var pathFind = new gamvas.AStarMap(); // create nodes var n1 = new AStarNode(10, 2); var n2 = new AStarNode(100, 50); // set connection between nodes n1.connect(n2); // add the nodes to the system pathFind.add(n1); pathFind.add(n2); // find the path between two points in space var path = pathFind.find(5, 1, 120, 40);
gamvas. | A flexible 3D node based A* pathfinding system |
Functions | |
add | Add a gamvas.AStarNode to the node system |
find | Find a path between two points in 2D space, or two gamvas.AStarNode elements |
add: function( n )
Add a gamvas.AStarNode to the node system
Keep in mind, that by just adding it, it is not connected to anything. See gamvas.AStarNode.connect
find: function( nxs, nys, xe, ye )
Find a path between two points in 2D space, or two gamvas.AStarNode elements
This function has two alternative ways to use it
map.find(x1, y1, x2, y2);
map.find(node1, node2);
var pathFind = new gamvas.AStarMap(); // create nodes var n1 = new AStarNode(10, 2); var n2 = new AStarNode(100, 50); var n3 = new AStarNode(250, 25); // set connection between nodes n1.connect(n2); n2.connect(n3); // add the nodes to the system pathFind.add(n1); pathFind.add(n2); pathFind.add(n3); // find the path using the nodes instead of using 3d coordinates var path = pathFind.find(n1, n3);
Add a gamvas.AStarNode to the node system
add: function( n )
Find a path between two points in 2D space, or two gamvas.AStarNode elements
find: function( nxs, nys, xe, ye )
Connect two nodes
connect: function( n, auto )