touching tips of index-fingers together means walk forward

This commit is contained in:
Seth Alves 2019-09-26 12:41:14 -07:00
parent 3d4de67c49
commit 2c535fa204
2 changed files with 71 additions and 1 deletions

View file

@ -35,7 +35,8 @@ var DEFAULT_SCRIPTS_COMBINED = [
"system/miniTablet.js",
"system/audioMuteOverlay.js",
"system/inspect.js",
"system/keyboardShortcuts/keyboardShortcuts.js"
"system/keyboardShortcuts/keyboardShortcuts.js",
"system/hand-track-walk.js"
];
var DEFAULT_SCRIPTS_SEPARATE = [
"system/controllers/controllerScripts.js",

View file

@ -0,0 +1,69 @@
/* global Script, Controller, Vec3 */
/* jshint loopfunc:true */
(function() {
var mappingName = 'hand-track-walk-' + Math.random();
var inputMapping = Controller.newMapping(mappingName);
var leftIndexPos = null;
var rightIndexPos = null;
var pinchOnBelowDistance = 0.016;
var pinchOffAboveDistance = 0.04;
var walking = false;
function updateWalking() {
if (leftIndexPos && rightIndexPos) {
var tipDistance = Vec3.distance(leftIndexPos, rightIndexPos);
if (tipDistance < pinchOnBelowDistance) {
print("qqqq walking");
walking = true;
} else if (walking && tipDistance > pinchOffAboveDistance) {
print("qqqq stopping");
walking = false;
}
}
}
function leftIndexChanged(pose) {
if (pose.valid) {
leftIndexPos = pose.translation;
} else {
leftIndexPos = null;
}
updateWalking();
}
function rightIndexChanged(pose) {
if (pose.valid) {
rightIndexPos = pose.translation;
} else {
rightIndexPos = null;
}
updateWalking();
}
function cleanUp() {
inputMapping.disable();
}
Script.scriptEnding.connect(function () {
cleanUp();
});
inputMapping.from(Controller.Standard.LeftHandIndex4).peek().to(leftIndexChanged);
inputMapping.from(Controller.Standard.RightHandIndex4).peek().to(rightIndexChanged);
inputMapping.from(function() {
if (walking) {
return -1;
} else {
return Controller.getActionValue(Controller.Standard.TranslateZ);
}
}).to(Controller.Actions.TranslateZ);
Controller.enableMapping(mappingName);
})();