Revert "Revert "beat warp in""

This reverts commit b683ece322.
This commit is contained in:
Kevin Ngo
2018-10-23 16:53:16 -07:00
parent 1c230f0c1b
commit c73bbbbfe5
3 changed files with 29 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
var SIGN_MATERIAL = {shader: 'flat', color: '#88f'};
import {BEAT_WARMUP_OFFSET, BEAT_WARMUP_SPEED} from '../constants/beat';
var auxObj3D = new THREE.Object3D();
const auxObj3D = new THREE.Object3D();
const SIGN_MATERIAL = {shader: 'flat', color: '#88f'};
/**
* Create beat from pool, collision detection, clipping planes.
@@ -38,6 +39,7 @@ AFRAME.registerComponent('beat', {
init: function () {
this.backToPool = false;
this.beams = document.getElementById('beams').components.beams;
this.beatBoundingBox = new THREE.Box3();
this.cutDirection = new THREE.Vector3();
this.destroyed = false;
@@ -47,6 +49,7 @@ AFRAME.registerComponent('beat', {
this.returnToPoolTimer = 800;
this.rotationAxis = new THREE.Vector3();
this.saberEls = this.el.sceneEl.querySelectorAll('[saber-controls]');
this.startPositionZ = undefined;
this.rightCutPlanePoints = [
new THREE.Vector3(),
new THREE.Vector3(),
@@ -97,9 +100,9 @@ AFRAME.registerComponent('beat', {
},
play: function () {
this.blockEl.object3D.visible = true;
this.destroyed = false;
this.el.object3D.visible = true;
this.blockEl.object3D.visible = true;
},
tock: function (time, timeDelta) {
@@ -109,7 +112,20 @@ AFRAME.registerComponent('beat', {
// Only check collisions when close.
const collisionZThreshold = -4;
if (this.el.object3D.position.z > collisionZThreshold) { this.checkCollisions(); }
this.el.object3D.position.z += this.data.speed * (timeDelta / 1000);
// Move.
if (this.el.object3D.position.z < this.startPositionZ) {
// Warm up / warp in.
this.el.object3D.position.z += BEAT_WARMUP_SPEED * (timeDelta / 1000);
if (this.el.object3D.position.z >= this.startPositionZ) {
this.beams.newBeam(this.data.color, this.el.object3D.position);
}
} else {
// Standard moving.
this.el.object3D.position.z += this.data.speed * (timeDelta / 1000);
}
// Check.
this.backToPool = this.el.object3D.position.z >= 2;
if (this.backToPool) { this.missHit(); }
}