Score system based on angle between projected saber vector and major planes
This commit is contained in:
@@ -693,6 +693,7 @@ AFRAME.registerComponent('beat', {
|
|||||||
saberControls.maxAnglePlaneX = 0;
|
saberControls.maxAnglePlaneX = 0;
|
||||||
saberControls.maxAnglePlaneY = 0;
|
saberControls.maxAnglePlaneY = 0;
|
||||||
saberControls.maxAnglePlaneXY = 0;
|
saberControls.maxAnglePlaneXY = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.wrongHit(hand);
|
this.wrongHit(hand);
|
||||||
}
|
}
|
||||||
@@ -709,6 +710,8 @@ AFRAME.registerComponent('beat', {
|
|||||||
var score = 0;
|
var score = 0;
|
||||||
var scoreText;
|
var scoreText;
|
||||||
var scoreEl;
|
var scoreEl;
|
||||||
|
// Harcoded temporarily.
|
||||||
|
const saberRotation = 3.14 / 12;
|
||||||
|
|
||||||
if (cutDirection === 'up' || cutDirection === 'down') {
|
if (cutDirection === 'up' || cutDirection === 'down') {
|
||||||
maxAngle = saberControls.maxAnglePlaneX;
|
maxAngle = saberControls.maxAnglePlaneX;
|
||||||
@@ -718,9 +721,9 @@ AFRAME.registerComponent('beat', {
|
|||||||
maxAngle = saberControls.maxAnglePlaneXY;
|
maxAngle = saberControls.maxAnglePlaneXY;
|
||||||
}
|
}
|
||||||
|
|
||||||
const angleBeforeHit = this.angleBeforeHit * 180 / Math.PI;
|
const angleBeforeHit = Math.max(0, (this.angleBeforeHit - saberRotation) * 180 / Math.PI);
|
||||||
const angleAfterHit = maxAngle * 180 / Math.PI;
|
const angleAfterHit = Math.max(0, (maxAngle - saberRotation) * 180 / Math.PI);
|
||||||
score += angleBeforeHit >= 90 ? 70 : (angleBeforeHit / 90) * 70;
|
score += angleBeforeHit >= 85 ? 70 : (angleBeforeHit / 80) * 70;
|
||||||
score += angleAfterHit >= 60 ? 30 : (angleAfterHit / 60) * 30;
|
score += angleAfterHit >= 60 ? 30 : (angleAfterHit / 60) * 30;
|
||||||
|
|
||||||
hitEventDetail.score = score;
|
hitEventDetail.score = score;
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ AFRAME.registerComponent('saber-controls', {
|
|||||||
var data = this.data;
|
var data = this.data;
|
||||||
|
|
||||||
this.boundingBox = new THREE.Box3();
|
this.boundingBox = new THREE.Box3();
|
||||||
this.bladeEl = el.querySelector('.blade');
|
|
||||||
this.controllerType = '';
|
this.controllerType = '';
|
||||||
this.xPlaneNormal = new THREE.Vector3(0, 1, 0);
|
this.xPlaneNormal = new THREE.Vector3(0, 1, 0);
|
||||||
this.yPlaneNormal = new THREE.Vector3(1, 0, 0);
|
this.yPlaneNormal = new THREE.Vector3(1, 0, 0);
|
||||||
@@ -24,6 +23,7 @@ AFRAME.registerComponent('saber-controls', {
|
|||||||
this.bladePosition = new THREE.Vector3();
|
this.bladePosition = new THREE.Vector3();
|
||||||
this.bladeVector = new THREE.Vector3();
|
this.bladeVector = new THREE.Vector3();
|
||||||
this.bladeTipPreviousPosition = new THREE.Vector3();
|
this.bladeTipPreviousPosition = new THREE.Vector3();
|
||||||
|
this.projectedBladeVector = new THREE.Vector3();
|
||||||
this.saberPosition = new THREE.Vector3();
|
this.saberPosition = new THREE.Vector3();
|
||||||
this.swinging = false;
|
this.swinging = false;
|
||||||
this.strokeCount = 0;
|
this.strokeCount = 0;
|
||||||
@@ -53,7 +53,6 @@ AFRAME.registerComponent('saber-controls', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
detectStroke: function (delta) {
|
detectStroke: function (delta) {
|
||||||
var bladeObject
|
|
||||||
var distance;
|
var distance;
|
||||||
var distanceSamples = this.distanceSamples;
|
var distanceSamples = this.distanceSamples;
|
||||||
var data = this.data;
|
var data = this.data;
|
||||||
@@ -62,19 +61,19 @@ AFRAME.registerComponent('saber-controls', {
|
|||||||
var strokeMinSpeed = this.swinging ? startSpeed : this.data.strokeMinSpeed;
|
var strokeMinSpeed = this.swinging ? startSpeed : this.data.strokeMinSpeed;
|
||||||
|
|
||||||
// Tip of the blade position in world coordinates.
|
// Tip of the blade position in world coordinates.
|
||||||
this.bladeTipPosition.set(0, 0.1, 0);
|
this.bladeTipPosition.set(0, 0, -0.8);
|
||||||
this.bladePosition.set(0, 0, 0);
|
this.bladePosition.set(0, 0, 0);
|
||||||
|
|
||||||
bladeObject = this.el.object3D;
|
const saberObj = this.el.object3D;
|
||||||
bladeObject.parent.updateMatrixWorld();
|
saberObj.parent.updateMatrixWorld();
|
||||||
bladeObject.localToWorld(this.bladeTipPosition);
|
saberObj.localToWorld(this.bladeTipPosition);
|
||||||
bladeObject.localToWorld(this.bladePosition);
|
saberObj.localToWorld(this.bladePosition);
|
||||||
|
|
||||||
// Angles between saber and major planes.
|
// Angles between saber and major planes.
|
||||||
this.bladeVector.copy(this.bladeTipPosition).sub(this.bladePosition).normalize();
|
this.bladeVector.copy(this.bladeTipPosition).sub(this.bladePosition).normalize();
|
||||||
var anglePlaneX = this.bladeVector.angleTo(this.xPlaneNormal);
|
var anglePlaneX = this.projectedBladeVector.copy(this.bladeTipPosition).projectOnPlane(this.xPlaneNormal).angleTo(this.bladeVector);
|
||||||
var anglePlaneY = this.bladeVector.angleTo(this.yPlaneNormal);
|
var anglePlaneY = this.projectedBladeVector.copy(this.bladeTipPosition).projectOnPlane(this.yPlaneNormal).angleTo(this.bladeVector);
|
||||||
var anglePlaneXY = this.bladeVector.angleTo(this.xyPlaneNormal);
|
var anglePlaneXY = this.projectedBladeVector.copy(this.bladeTipPosition).projectOnPlane(this.xyPlaneNormal).angleTo(this.bladeVector);
|
||||||
|
|
||||||
// Distance covered but the saber tip in one frame.
|
// Distance covered but the saber tip in one frame.
|
||||||
distance = this.bladeTipPreviousPosition.sub(this.bladeTipPosition).length() * 1000000;
|
distance = this.bladeTipPreviousPosition.sub(this.bladeTipPosition).length() * 1000000;
|
||||||
@@ -86,8 +85,7 @@ AFRAME.registerComponent('saber-controls', {
|
|||||||
this.distanceSamples.push(distance);
|
this.distanceSamples.push(distance);
|
||||||
this.accumulatedDistance += distance;
|
this.accumulatedDistance += distance;
|
||||||
|
|
||||||
// Filter out saber movements that are too slow. Too slow or small angle is considered wrong hit.
|
// Filter out saber movements that are too slow. Too slow is considered wrong hit.
|
||||||
// Cap stroke to 180 degrees.
|
|
||||||
if (this.accumulatedDistance > this.data.strokeMinSpeed) {
|
if (this.accumulatedDistance > this.data.strokeMinSpeed) {
|
||||||
// Saber has to move more than strokeMinAngle to consider a swing.
|
// Saber has to move more than strokeMinAngle to consider a swing.
|
||||||
// This filters out unintentional swings.
|
// This filters out unintentional swings.
|
||||||
@@ -115,7 +113,6 @@ AFRAME.registerComponent('saber-controls', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
endStroke: function () {
|
endStroke: function () {
|
||||||
// console.log("MaxAngle " + this.maxAnglePlaneX * 180 / Math.PI);
|
|
||||||
this.el.emit('strokeend');
|
this.el.emit('strokeend');
|
||||||
if (this.swinging) { return; }
|
if (this.swinging) { return; }
|
||||||
this.accumulatedDistance = 0;
|
this.accumulatedDistance = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user