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