From 709a40516d5ffcc2e3fc5b25c152f8ba3e91c970 Mon Sep 17 00:00:00 2001 From: Philip Rosedale <philip@highfidelity.io> Date: Sat, 29 Nov 2014 12:17:38 -0800 Subject: [PATCH] Add auto-turn of body when head is beyond 45 degrees --- examples/headMove.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/examples/headMove.js b/examples/headMove.js index df5c858b46..4d2e4ded07 100644 --- a/examples/headMove.js +++ b/examples/headMove.js @@ -19,6 +19,7 @@ var warpPosition = { x: 0, y: 0, z: 0 }; var hipsToEyes; var restoreCountdownTimer; +var headTurningTimer = 0.0; // Overlays to show target location @@ -168,6 +169,20 @@ function update(deltaTime) { restoreCountDownTimer = 0.0; } } + var HEAD_TURN_TIME = 0.10; + var HEAD_TURN_DEGREES = 4.0; + var HEAD_TURN_START_ANGLE = 45.0; + var currentYaw = MyAvatar.getHeadFinalYaw(); + if (Math.abs(currentYaw) > HEAD_TURN_START_ANGLE) { + headTurningTimer += deltaTime; + if (headTurningTimer > HEAD_TURN_TIME) { + headTurningTimer = 0.0; + MyAvatar.orientation = Quat.multiply(Quat.fromPitchYawRollDegrees(0, (currentYaw > 0) ? HEAD_TURN_DEGREES: -HEAD_TURN_DEGREES, 0), + MyAvatar.orientation); + } + } else { + headTurningTimer = 0.0; + } } Controller.keyPressEvent.connect(function(event) {