mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 01:12:48 +02:00
touching tips of index-fingers together means walk forward
This commit is contained in:
parent
3d4de67c49
commit
2c535fa204
2 changed files with 71 additions and 1 deletions
|
@ -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",
|
||||
|
|
69
scripts/system/hand-track-walk.js
Normal file
69
scripts/system/hand-track-walk.js
Normal 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);
|
||||
})();
|
Loading…
Reference in a new issue