From 44f0b8bd6043484d9aadb14e2e5c2171e1935f98 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Sun, 2 Jul 2017 11:41:33 +0100 Subject: [PATCH] Support for Oculus & Vive - cleaned up some code, using Script.connect instead of setInterval --- .../marketplace/rocketHands/rockethands.js | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index 678e51565d..a4a4cf777c 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -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); }()); \ No newline at end of file