Skip to content

RandomPathBehavior

Oğuz Eroğlu edited this page Aug 19, 2020 · 5 revisions

Demo

This demo uses RandomPathBehavior as the bots are randomly walking through the map.

Definition

RandomPathBehavior chooses 2 random vertices from a graph, computes the shortest path between these two vertices, then delegates to PathFollowingBehavior to follow through the computed path. When the distance between the steerable and the target vertex is less than satisfactionRadius, RandomPathBehavior chooses another 2 random vertices.

Usage

// create a steerable
var steerable = new Kompute.Steerable("steerable1", new Kompute.Vector3D(), new Kompute.Vector3D(10, 10, 10));

// set the max acceleration and the speed of the steerable
steerable.maxAcceleration = 100;
steerable.maxSpeed = 100;

// create a graph
var graph = new Kompute.Graph();
    
graph.addVertex(new Kompute.Vector3D(100, 200, 300));
graph.addVertex(new Kompute.Vector3D(400, 500, 600));

graph.addEdge(new Kompute.Vector3D(100, 200, 300), new Kompute.Vector3D(400, 500, 600));

// create a World
var world = new Kompute.World(1000, 1000, 1000, 10);

// insert the graph into the World due to performance optimisation reasons
world.insertGraph(graph);

// create an instance of RandomPathBehavior
var randomPathBehavior = new Kompute.RandomPathBehavior({ graph: graph, satisfactionRadius: 50 });

// set the behavior
steerable.setBehavior(randomPathBehavior);

Clone this wiki locally