From 6fe9573801f8a7adbb78d140cc554d636dccbfbd Mon Sep 17 00:00:00 2001 From: Oguz Date: Sat, 8 Aug 2020 11:48:21 +0200 Subject: [PATCH] AvoidBehavior should not consider Vertices as nearby entities --- js/steering/behavior/AvoidBehavior.js | 6 ++++++ test/steering/behavior/AvoidBehaviorTest.js | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/js/steering/behavior/AvoidBehavior.js b/js/steering/behavior/AvoidBehavior.js index d248ba0..74b9212 100644 --- a/js/steering/behavior/AvoidBehavior.js +++ b/js/steering/behavior/AvoidBehavior.js @@ -1,6 +1,7 @@ import { SteeringBehavior } from "./SteeringBehavior"; import { Box } from "../../core/Box"; import { Vector3D } from "../../core/Vector3D"; +import { Vertex } from "../../core/Vertex"; import { VectorPool } from "../../core/VectorPool"; import { logger } from "../../debug/Logger"; @@ -34,6 +35,11 @@ AvoidBehavior.prototype.findMostThreateningObstacle = function(steerable){ box.expandByPoint(steerable.box.max); steerable.executeForEachCloseEntity(function(entity){ + + if (entity instanceof Vertex){ + return; + } + if (box.intersectsBox(entity.box)){ if (!mostThreatening){ mostThreatening = entity; diff --git a/test/steering/behavior/AvoidBehaviorTest.js b/test/steering/behavior/AvoidBehaviorTest.js index 77f12b6..b9198f1 100644 --- a/test/steering/behavior/AvoidBehaviorTest.js +++ b/test/steering/behavior/AvoidBehaviorTest.js @@ -57,6 +57,13 @@ describe("AvoidBehavior", function(){ var avoidBehavior = new Kompute.AvoidBehavior({ maxSeeAhead: 50000, maxAvoidForce: 100 }); expect(avoidBehavior.findMostThreateningObstacle(steerable)).to.eql(null); + + var graph = new Kompute.Graph(); + graph.addVertex(new Kompute.Vector3D(0, 0, 0)); + + world.insertGraph(graph); + + expect(avoidBehavior.findMostThreateningObstacle(steerable)).to.eql(null); }); it("should find most mostThreatening if not going towards the obstacle [hits obstacle by size]", function(){