Skip to content

AvoidBehavior

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

Demo

This demo uses AvoidBehavior combined with SeekBehavior when the bots are switched to shooting mode.

Definition

AvoidBehavior makes a steerable avoid other entities and steerables lying in its path. The steerable does not try to avoid entities that are more than maxSeeAhead units away. When a threatening entity is detected, the steerable is accelerated maxAvoidForce units away from the threatening entity.

Usage

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

// create an obstacle
var obstacle = new Kompute.Entity("entity1", new Kompute.Vector3D(0, 0, 20), new Kompute.Vector3D(10, 10, 10));

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

// insert entities to world
world.insertEntity(steerable);
world.insertEntity(obstacle);

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

// create an instance of AvoidBehavior
var avoidBehavior = new Kompute.AvoidBehavior({ maxSeeAhead: 500, maxAvoidForce: 100 });

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

Clone this wiki locally