Skip to content

Commit

Permalink
HideBehavior should not consider Vertex instances when looking for hi…
Browse files Browse the repository at this point in the history
…ding spots
  • Loading branch information
oguzeroglu committed Aug 8, 2020
1 parent 57bfbfc commit faa98a1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion js/steering/behavior/HideBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ArriveBehavior } from "./ArriveBehavior";
import { VectorPool } from "../../core/VectorPool";
import { Vector3D } from "../../core/Vector3D";
import { Steerable } from "../Steerable";
import { Vertex } from "../../core/Vertex";
import { logger } from "../../debug/Logger";

var vectorPool = new VectorPool(10);
Expand Down Expand Up @@ -63,7 +64,7 @@ HideBehavior.prototype.findHidingSpot = function(steerable){
var self = this;

steerable.executeForEachCloseEntity(function(entity){
if (entity instanceof Steerable){
if (entity instanceof Steerable || entity instanceof Vertex){
return;
}

Expand Down
27 changes: 27 additions & 0 deletions test/steering/behavior/HideBehaviorTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,31 @@ describe("HideBehavior", function(){
expect(result.linear).to.eql(new Kompute.Vector3D());
expect(loggedMsg).to.eql("[HideBehavior]: Target entity is out of threat distance. (steerable1)");
});

it("should not consider Vertex instances when finding hiding spots", function(){
var steerable = new Kompute.Steerable("steerable1", new Kompute.Vector3D(), new Kompute.Vector3D(10, 10, 10));
var steerable2 = new Kompute.Steerable("steerable2", new Kompute.Vector3D(100, 0, 0), new Kompute.Vector3D(10, 10, 10));

var world = new Kompute.World(1000, 1000, 1000, 50);
world.insertEntity(steerable);
world.insertEntity(steerable2);

steerable.setHideTargetEntity(steerable2);

var hideBehavior = new Kompute.HideBehavior({
arriveSatisfactionRadius: 50,
arriveSlowDownRadius: 100,
hideDistance: 150,
threatDistance: 2000
});

var graph = new Kompute.Graph();
graph.addVertex(new Kompute.Vector3D(5, 0, 0));

world.insertGraph(graph);

hideBehavior.findHidingSpot(steerable);

expect(hideBehavior.hidingSpotFound).to.eql(false);
});
});

0 comments on commit faa98a1

Please sign in to comment.