Skip to content

CohesionBehavior

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

Definition

CohesionBehavior calculates the center position of each nearby steerable for given steerable, then makes the steerable seek towards that position. Use this behavior to keep a group of steerables together.

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(30, 20, 100), new Kompute.Vector3D(10, 10, 10));

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

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

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

// create an instance of CohesionBehavior
var cohesionBehavior = new Kompute.CohesionBehavior();

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

Clone this wiki locally