Skip to content

Commit

Permalink
excludeFromHide flag
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzeroglu committed Aug 8, 2020
1 parent cec0ed1 commit e2f9dec
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/steering/behavior/HideBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ HideBehavior.prototype.findHidingSpot = function(steerable){
var self = this;

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

Expand Down
28 changes: 28 additions & 0 deletions test/steering/behavior/HideBehaviorTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,32 @@ describe("HideBehavior", function(){

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

it("should not consider entities with excludeFromHide flag 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 entity = new Kompute.Entity("entity1", new Kompute.Vector3D(5, 0, 0), new Kompute.Vector3D(10, 10, 10));

world.insertEntity(entity);

entity.excludeFromHide = true;

hideBehavior.findHidingSpot(steerable);

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

0 comments on commit e2f9dec

Please sign in to comment.