diff --git a/package-lock.json b/package-lock.json index 2cb1a811f83c65ef23aa22a205035168273700d0..f5c74cb53cd9f34a30c6840610e485aa10b1b94a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12632,7 +12632,7 @@ } }, "three-pathfinding": { - "version": "github:mozillareality/three-pathfinding#8ea5fed7418a1e93a7ba8917a622f871477169d9", + "version": "github:mozillareality/three-pathfinding#a52f437eaaf1b608c5f7fed046846bdbd79c75e7", "from": "github:mozillareality/three-pathfinding#hubs/master" }, "three-to-cannon": { diff --git a/src/components/character-controller.js b/src/components/character-controller.js index 36c7c641fc58cc205278b635abef13fc4af8d699..28e48e6c2cb1d37615a84a98c5b793f89efe899d 100644 --- a/src/components/character-controller.js +++ b/src/components/character-controller.js @@ -171,29 +171,30 @@ AFRAME.registerComponent("character-controller", { console.warn("character-controller", msg); }, - _updateNavState: function(pos, forceUpdate) { + _setNavNode: function(pos) { + if (this.navNode !== null) return; const { pathfinder } = this.el.sceneEl.systems.nav; - if (this.navGroup === null || forceUpdate) { - this.navGroup = pathfinder.getGroup(this.navZone, pos, true); - } - if (this.navNode === null || forceUpdate) { - this.navNode = - pathfinder.getClosestNode(pos, this.navZone, this.navGroup, true) || - pathfinder.getClosestNode(pos, this.navZone, this.navGroup); - } + this.navNode = + pathfinder.getClosestNode(pos, this.navZone, this.navGroup, true) || + pathfinder.getClosestNode(pos, this.navZone, this.navGroup); }, setPositionOnNavMesh: function(start, end, object3D) { const { pathfinder } = this.el.sceneEl.systems.nav; if (!(this.navZone in pathfinder.zones)) return; - this._updateNavState(end); + if (this.navGroup === null) { + this.navGroup = pathfinder.getGroup(this.navZone, end, true, true); + } + this._setNavNode(end); this.navNode = pathfinder.clampStep(start, end, this.navNode, this.navZone, this.navGroup, object3D.position); }, resetPositionOnNavMesh: function(position, navPosition, object3D) { const { pathfinder } = this.el.sceneEl.systems.nav; if (!(this.navZone in pathfinder.zones)) return; - this._updateNavState(navPosition, true); + this.navGroup = pathfinder.getGroup(this.navZone, navPosition, true); + this.navNode = null; + this._setNavNode(navPosition); object3D.position.copy(navPosition); },