Skip to content

Commit

Permalink
Merge pull request #437 from c-frame/moved-event
Browse files Browse the repository at this point in the history
[movement-controls] Emit a moved event on each tick when you are moving
  • Loading branch information
vincentfretin authored Dec 2, 2023
2 parents a92adf0 + 864e133 commit d10fe45
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 22 deletions.
14 changes: 10 additions & 4 deletions dist/aframe-extras.controls.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/aframe-extras.controls.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/aframe-extras.controls.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/aframe-extras.controls.min.js.map

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions dist/aframe-extras.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/aframe-extras.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/aframe-extras.loaders.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/aframe-extras.loaders.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/aframe-extras.loaders.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/aframe-extras.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/aframe-extras.min.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/controls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ With physics-based movement.
| constrainToNavMesh | false | Whether to use navigation system to clamp movement. |
| camera | [camera] | Camera element used for heading of the camera rig. |


## Events

- The `movement-controls` component emits a `moved` event on the entity with evt.detail.velocity (vec3).

## Customizing movement-controls

To implement your custom controls, define a component and override one or more methods:
Expand Down
14 changes: 10 additions & 4 deletions src/controls/movement-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* @author Don McCurdy <dm@donmccurdy.com>
*/

const COMPONENT_SUFFIX = '-controls',
MAX_DELTA = 0.2, // ms
EPS = 10e-6;
const COMPONENT_SUFFIX = '-controls';
const MAX_DELTA = 0.2; // ms
const EPS = 10e-6;
const MOVED = 'moved';

module.exports = AFRAME.registerComponent('movement-controls', {

Expand All @@ -32,12 +33,13 @@ module.exports = AFRAME.registerComponent('movement-controls', {
init: function () {
const el = this.el;
if (!this.data.camera) {
this.data.camera = el.querySelector('[camera]')
this.data.camera = el.querySelector('[camera]');
}
this.velocityCtrl = null;

this.velocity = new THREE.Vector3();
this.heading = new THREE.Quaternion();
this.eventDetail = {};

// Navigation
this.navGroup = null;
Expand Down Expand Up @@ -208,6 +210,10 @@ module.exports = AFRAME.registerComponent('movement-controls', {
velocity.y = 0;
velocity.z = vector2.y;
}
if (velocity.x !== 0 || velocity.y !== 0 || velocity.z !== 0) {
this.eventDetail.velocity = velocity;
this.el.emit(MOVED, this.eventDetail);
}
}
};

Expand Down

0 comments on commit d10fe45

Please sign in to comment.