Skip to content
Snippets Groups Projects
Commit 20c4f72d authored by Kevin Lee's avatar Kevin Lee
Browse files

cleanup nav-mesh stuff in character-controller

parent 4a12d78f
No related branches found
No related tags found
No related merge requests found
...@@ -83,8 +83,8 @@ AFRAME.registerComponent("character-controller", { ...@@ -83,8 +83,8 @@ AFRAME.registerComponent("character-controller", {
const position = new THREE.Vector3(); const position = new THREE.Vector3();
const currentPosition = new THREE.Vector3(); const currentPosition = new THREE.Vector3();
const movementVector = new THREE.Vector3(); const movementVector = new THREE.Vector3();
const end = new THREE.Vector3(); const start = new THREE.Vector3();
const clampedEnd = new THREE.Vector3(); let navGroup, navNode;
return function(t, dt) { return function(t, dt) {
const deltaSeconds = dt / 1000; const deltaSeconds = dt / 1000;
...@@ -93,6 +93,8 @@ AFRAME.registerComponent("character-controller", { ...@@ -93,6 +93,8 @@ AFRAME.registerComponent("character-controller", {
const distance = this.data.groundAcc * deltaSeconds; const distance = this.data.groundAcc * deltaSeconds;
const rotationDelta = this.data.rotationSpeed * this.angularVelocity * deltaSeconds; const rotationDelta = this.data.rotationSpeed * this.angularVelocity * deltaSeconds;
start.copy(root.position);
// Other aframe components like teleport-controls set position/rotation/scale, not the matrix, so we need to make sure to compose them back into the matrix // Other aframe components like teleport-controls set position/rotation/scale, not the matrix, so we need to make sure to compose them back into the matrix
root.updateMatrix(); root.updateMatrix();
...@@ -137,17 +139,13 @@ AFRAME.registerComponent("character-controller", { ...@@ -137,17 +139,13 @@ AFRAME.registerComponent("character-controller", {
this.pendingSnapRotationMatrix.identity(); // Revert to identity this.pendingSnapRotationMatrix.identity(); // Revert to identity
//copied from aframe-extras movement-controls //copied from aframe-extras movement-controls
if (this.velocity.lengthSq() > EPS) { const nav = this.el.sceneEl.systems.nav;
let start = root.position; if (nav.navMesh && this.velocity.lengthSq() > EPS) {
end.copy(this.velocity).multiplyScalar(dt / 1000).add(start); if (!navGroup) {
const nav = this.el.sceneEl.systems.nav; navGroup = nav.getGroup(start);
this.navGroup = this.navGroup || nav.getGroup(start); }
this.navNode = this.navNode || nav.getNode(start, this.navGroup); navNode = navNode || nav.getNode(start, navGroup);
this.navNode = nav.clampStep(start, end, this.navGroup, this.navNode, clampedEnd); navNode = nav.clampStep(start, root.position, navGroup, navNode, root.position);
root.position.copy(clampedEnd);
root.position.x += this.velocity.x * dt / 1000;
root.position.y += this.velocity.y * dt / 1000;
root.z += this.velocity.z * dt / 1000;
} else { } else {
this.el.setAttribute("position", root.position); this.el.setAttribute("position", root.position);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment