Support for Oculus & Vive - cleaned up some code, using Script.connect instead of setInterval

This commit is contained in:
Cain Kilgore 2017-07-02 11:41:33 +01:00
parent a693a61ec8
commit 44f0b8bd60

View file

@ -13,15 +13,18 @@
(function() { (function() {
var isRocketing = false; var isRocketing = false;
MyAvatar.motorVelocity = 0;
Script.setInterval(function() { function checkRocketting() {
if (Controller.Hardware.Vive) { if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) {
var rightHand = Controller.getPoseValue(Controller.Hardware.Vive.RightHand); var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand);
var getHip = MyAvatar.getJointPosition("Hips"); var rightHand = Controller.getPoseValue(Controller.Standard.RightHand);
var worldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation));
var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation));
if ((worldControllerPos.y > (getHip.y - 0.1)) && (worldControllerPos.y < (getHip.y + 0.1))) { var hipPosition = MyAvatar.getJointPosition("Hips");
if (rightHand.rotation.y < 0.25 && rightHand.rotation.y > -0.25) {
if ((leftWorldControllerPos.y > (hipPosition.y - 0.1)) && (leftWorldControllerPos.y < (hipPosition.y + 0.1)) && rightWorldControllerPos.y > (hipPosition.y - 0.1) && (rightWorldControllerPos.y < (hipPosition.y + 0.1))) {
if (leftHand.rotation.y < 0.25 && leftHand.rotation.y > -0.25 && rightHand.rotation.y < 0.25 && rightHand.rotation.y > -0.25) {
isRocketing = true; isRocketing = true;
Controller.triggerHapticPulse(0.1, 120, 2); Controller.triggerHapticPulse(0.1, 120, 2);
MyAvatar.motorReferenceFrame = "world"; MyAvatar.motorReferenceFrame = "world";
@ -31,13 +34,20 @@
} }
MyAvatar.motorVelocity = moveVector; MyAvatar.motorVelocity = moveVector;
MyAvatar.motorTimescale = 1.0; MyAvatar.motorTimescale = 1.0;
} else { } else {
if (isRocketing) { if (isRocketing) {
MyAvatar.motorVelocity = 0; MyAvatar.motorVelocity = 0;
isRocketing = false; isRocketing = false;
} }
} }
} else {
if (isRocketing) {
MyAvatar.motorVelocity = 0;
isRocketing = false;
}
} }
} }
}, 100); };
Script.update.connect(checkRocketting);
}()); }());