Skip to content

AlignBehavior

Oğuz Eroğlu edited this page Jun 13, 2020 · 1 revision

Definition

AlignBehavior scans each nearby steerable for given steerable, calculates the average speed of nearby steerables, and produces an acceleration that makes the steerable reach to the calculated average speed. Cars moving along roads demonstrate this type of behavior.

Usage

// create steerables
var steerable = new Kompute.Steerable("steerable1", new Kompute.Vector3D(), new Kompute.Vector3D(10, 10, 10));
var steerable2 = new Kompute.Steerable("steerable2", new Kompute.Vector3D(10, 10, 10), new Kompute.Vector3D(10, 10, 10));
var steerable3 = new Kompute.Steerable("steerable3", new Kompute.Vector3D(-10, -10, -10), new Kompute.Vector3D(10, 10, 10));

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

// insert steerables into the world
world.insertEntity(steerable);
world.insertEntity(steerable2);
world.insertEntity(steerable3);

// create an instance of AlignBehavior
var alignBehavior = new Kompute.AlignBehavior();

// set the align behavior
steerable.setBehavior(alignBehavior);

Clone this wiki locally