Skip to content

PathFollowingBehavior

Oğuz Eroğlu edited this page Aug 9, 2020 · 4 revisions

Demo

This demo includes this behavior for the user-controlled character.

Definition

PathFollowingBehavior makes a steerable follow a path by making it seek towards each waypoint of the path respectively. The steerable is considered to reach to a certain waypoint if the distance between its position and the waypoint position is less than satisfactionRadius. It then seeks toward the next waypoint, until the path is finished (if it's not a looping path).

If a jump descriptor is added to given path, this behavior automatically initiates a jump when the jump take off position is on the way. In that case, the steerable automatically continues with the PathFollowingBehavior when the jump is completed (the steerable landed to the landing position).

Usage

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

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

// Create a Path
var path = new Kompute.Path();

path.addWaypoint(new Kompute.Vector3D(0, 0, 0));
path.addWaypoint(new Kompute.Vector3D(100, 200, 300));

// Create an instance of PathFollowingBehavior
var pathFollowingBehavior = new Kompute.PathFollowingBehavior({ path: path, satisfactionRadius: 50 });

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

// listen to path finish if necessary
path.finishCallback = function(){
  console.log("Path is finished.");
};