Make strokeDuration / strokeSpeed configurable on the component

This commit is contained in:
Diego Marcos
2018-10-15 16:07:29 -07:00
parent e94ca0d8c6
commit 5acf9433ed

View File

@@ -2,7 +2,9 @@
schema: {
bladeEnabled: {default: false},
hand: {default: 'right', oneOf: ['left', 'right']},
isPaused: {default: false}
isPaused: {default: false},
strokeDuration: {default: 100},
strokeSpeed: {default: 2000}
},
init: function () {
@@ -41,6 +43,7 @@
detectStroke: function (delta) {
var bladeObject
var distance;
var data = this.data;
this.bladeTipPosition.set(0, 0.4, 0);
bladeObject = this.el.object3D;
bladeObject.parent.updateMatrixWorld();
@@ -50,12 +53,12 @@
return;
}
distance = this.bladeTipPosition.distanceTo(this.bladeTipPreviousPosition) * 1000000;
if (distance > 2000) {
if (distance > data.strokeSpeed) {
if (!this.startSwinging) {
this.startSwinging = true;
this.swingDuration = 0;
}
if (this.swingDuration > 100) {
if (this.swingDuration > data.strokeDuration) {
this.swinging = true;
} else {
this.swingDuration += delta;