-
Notifications
You must be signed in to change notification settings - Fork 5
AStar
Oğuz Eroğlu edited this page Jun 15, 2020
·
4 revisions
AStar
is a Kompute implementation of A* search algorithmto find the shortest path between two vertices of given Graph. This class is internally used by RandomPathBehavior however may be used manually as well.
// create a Graph
var graph = new Kompute.Graph();
// define vertices
var vertex1 = new Kompute.Vector3D(100, 0, 0);
var vertex2 = new Kompute.Vector3D(200, 0, 0);
var vertex3 = new Kompute.Vector3D(300, 0, 0);
// add vertices to graph
graph.addVertex(vertex1);
graph.addVertex(vertex2);
graph.addVertex(vertex3);
// add edges to graph
graph.addEdge(vertex1, vertex2);
graph.addEdge(vertex2, vertex3);
// create an instance of AStar
var aStar = new Kompute.AStar(graph);
// Find the shortest path from vertex1 to vertex3
var path = aStar.findShortestPath(vertex1, vertex3);
// findShortesPath returns false if there's not a possible path
console.log(aStar.findShortestPath(vertex3, vertex1); // prints false
In order to pipe the output of AStar
to PathFollowingBehavior aStar.path
property may be used:
var pathFollowingBehavior = new Kompute.PathFollowingBehavior({
satisfactionRadius: 5,
path: aStar.path
});
steerable.setBehavior(pathFollowingBehavior);
This refreshes the PathFollowingBehavior
everytime the shortest path is computed.
A JumpDescriptor
may be inserted into the Graph
in order to automatically activate jump behavior while following the Path
constructed by the AStar
. See here.
- Core
- Path
-
Steering Behaviors
- AlignBehavior
- ArriveBehavior
- AvoidBehavior
- BlendedSteeringBehavior
- CohesionBehavior
- EvadeBehavior
- FleeBehavior
- HideBehavior
- JumpBehavior
- LookWhereYouAreGoingBehavior
- PathFollowingBehavior
- PrioritySteeringBehavior
- PursueBehavior
- RandomPathBehavior
- RandomWaypointBehavior
- SeekBehavior
- SeparationBehavior
- Wander2DBehavior
- Wander3DBehavior
- Math
- Extra