History

Add support for smooth turning in tutorial

Ryan Huffman committed 10 years ago

Commit 68735761 parent 8350dc41 file · +37 −8Browse files

Showing the changes to tutorial/tutorial.js (1 of 1 file). Show all

Unified · Split

tutorial/tutorial.js+37−8
@@ -715,7 +715,8 @@ var stepTurnAround = function(name) { · 714 unmodified lines
715715 this.tempTag = name + "-temporary";
716716
717717 this.onActionBound = this.onAction.bind(this);
718− this.numTimesTurnPressed = 0;
718+ this.numTimesSnapTurnPressed = 0;
719+ this.numTimesSmoothTurnPressed = 0;
719720 }
720721 stepTurnAround.prototype = {
721722 start: function(onFinish) {
@@ -724,19 +725,26 @@ stepTurnAround.prototype = { · 2 unmodified lines
724725
725726 showEntitiesWithTag(this.tag);
726727
727− this.numTimesTurnPressed = 0;
728+ this.numTimesSnapTurnPressed = 0;
729+ this.numTimesSmoothTurnPressed = 0;
730+ this.smoothTurnDown = false;
728731 Controller.actionEvent.connect(this.onActionBound);
729732
730733 this.interval = Script.setInterval(function() {
731− debug("TurnAround | Checking if finished", this.numTimesTurnPressed);
734+ debug("TurnAround | Checking if finished",
735+ this.numTimesSnapTurnPressed, this.numTimesSmoothTurnPressed);
732736 var FORWARD_THRESHOLD = 90;
733− var REQ_NUM_TIMES_PRESSED = 3;
737+ var REQ_NUM_TIMES_SNAP_TURN_PRESSED = 3;
738+ var REQ_NUM_TIMES_SMOOTH_TURN_PRESSED = 2;
734739
735740 var dir = Quat.getFront(MyAvatar.orientation);
736741 var angle = Math.atan2(dir.z, dir.x);
737742 var angleDegrees = ((angle / Math.PI) * 180);
738743
739− if (this.numTimesTurnPressed >= REQ_NUM_TIMES_PRESSED && Math.abs(angleDegrees) < FORWARD_THRESHOLD) {
744+ var hasTurnedEnough = this.numTimesSnapTurnPressed >= REQ_NUM_TIMES_SNAP_TURN_PRESSED
745+ || this.numTimesSmoothTurnPressed >= REQ_NUM_TIMES_SMOOTH_TURN_PRESSED;
746+ var facingForward = Math.abs(angleDegrees) < FORWARD_THRESHOLD
747+ if (hasTurnedEnough && facingForward) {
740748 Script.clearInterval(this.interval);
741749 this.interval = null;
742750 playSuccessSound();
@@ -745,10 +753,31 @@ stepTurnAround.prototype = { · 2 unmodified lines
745753 }.bind(this), 100);
746754 },
747755 onAction: function(action, value) {
748− var STEP_YAW_ACTION = 6;
756+ // NOTE(Huffman, 11/2/16): The checks below are for backward compatibility
757+ // Old versions of High Fidelity returned invalid action ids from
758+ // Controller.Actions.Yaw/StepYaw which were above 10000. If they are
759+ // above 10000 then we can assume we are on an old version and hard-code
760+ // the values. Eventually we should remove these checks.
761+ var STEP_YAW_ACTION = Controller.Actions.StepYaw;
762+ if (STEP_YAW_ACTION > 10000) {
763+ STEP_YAW_ACTION = 6;
764+ }
765+ var SMOOTH_YAW_ACTION = Controller.Actions.Yaw;
766+ if (SMOOTH_YAW_ACTION > 10000) {
767+ SMOOTH_YAW_ACTION = 4;
768+ }
769+
749770 if (action == STEP_YAW_ACTION && value != 0) {
750− debug("TurnAround | Got yaw action");
751− this.numTimesTurnPressed += 1;
771+ debug("TurnAround | Got step yaw action");
772+ ++this.numTimesSnapTurnPressed;
773+ } else if (action == SMOOTH_YAW_ACTION) {
774+ debug("TurnAround | Got smooth yaw action");
775+ if (this.smoothTurnDown && value === 0) {
776+ this.smoothTurnDown = false;
777+ ++this.numTimesSmoothTurnPressed;
778+ } else if (!this.smoothTurnDown && value !== 0) {
779+ this.smoothTurnDown = true;
780+ }
752781 }
753782 },
754783 cleanup: function() {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t