mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:21:16 +02:00
Add support for smooth turning in tutorial
This commit is contained in:
parent
8350dc47f4
commit
68735763df
1 changed files with 37 additions and 8 deletions
|
@ -715,7 +715,8 @@ var stepTurnAround = function(name) {
|
||||||
this.tempTag = name + "-temporary";
|
this.tempTag = name + "-temporary";
|
||||||
|
|
||||||
this.onActionBound = this.onAction.bind(this);
|
this.onActionBound = this.onAction.bind(this);
|
||||||
this.numTimesTurnPressed = 0;
|
this.numTimesSnapTurnPressed = 0;
|
||||||
|
this.numTimesSmoothTurnPressed = 0;
|
||||||
}
|
}
|
||||||
stepTurnAround.prototype = {
|
stepTurnAround.prototype = {
|
||||||
start: function(onFinish) {
|
start: function(onFinish) {
|
||||||
|
@ -724,19 +725,26 @@ stepTurnAround.prototype = {
|
||||||
|
|
||||||
showEntitiesWithTag(this.tag);
|
showEntitiesWithTag(this.tag);
|
||||||
|
|
||||||
this.numTimesTurnPressed = 0;
|
this.numTimesSnapTurnPressed = 0;
|
||||||
|
this.numTimesSmoothTurnPressed = 0;
|
||||||
|
this.smoothTurnDown = false;
|
||||||
Controller.actionEvent.connect(this.onActionBound);
|
Controller.actionEvent.connect(this.onActionBound);
|
||||||
|
|
||||||
this.interval = Script.setInterval(function() {
|
this.interval = Script.setInterval(function() {
|
||||||
debug("TurnAround | Checking if finished", this.numTimesTurnPressed);
|
debug("TurnAround | Checking if finished",
|
||||||
|
this.numTimesSnapTurnPressed, this.numTimesSmoothTurnPressed);
|
||||||
var FORWARD_THRESHOLD = 90;
|
var FORWARD_THRESHOLD = 90;
|
||||||
var REQ_NUM_TIMES_PRESSED = 3;
|
var REQ_NUM_TIMES_SNAP_TURN_PRESSED = 3;
|
||||||
|
var REQ_NUM_TIMES_SMOOTH_TURN_PRESSED = 2;
|
||||||
|
|
||||||
var dir = Quat.getFront(MyAvatar.orientation);
|
var dir = Quat.getFront(MyAvatar.orientation);
|
||||||
var angle = Math.atan2(dir.z, dir.x);
|
var angle = Math.atan2(dir.z, dir.x);
|
||||||
var angleDegrees = ((angle / Math.PI) * 180);
|
var angleDegrees = ((angle / Math.PI) * 180);
|
||||||
|
|
||||||
if (this.numTimesTurnPressed >= REQ_NUM_TIMES_PRESSED && Math.abs(angleDegrees) < FORWARD_THRESHOLD) {
|
var hasTurnedEnough = this.numTimesSnapTurnPressed >= REQ_NUM_TIMES_SNAP_TURN_PRESSED
|
||||||
|
|| this.numTimesSmoothTurnPressed >= REQ_NUM_TIMES_SMOOTH_TURN_PRESSED;
|
||||||
|
var facingForward = Math.abs(angleDegrees) < FORWARD_THRESHOLD
|
||||||
|
if (hasTurnedEnough && facingForward) {
|
||||||
Script.clearInterval(this.interval);
|
Script.clearInterval(this.interval);
|
||||||
this.interval = null;
|
this.interval = null;
|
||||||
playSuccessSound();
|
playSuccessSound();
|
||||||
|
@ -745,10 +753,31 @@ stepTurnAround.prototype = {
|
||||||
}.bind(this), 100);
|
}.bind(this), 100);
|
||||||
},
|
},
|
||||||
onAction: function(action, value) {
|
onAction: function(action, value) {
|
||||||
var STEP_YAW_ACTION = 6;
|
// NOTE(Huffman, 11/2/16): The checks below are for backward compatibility
|
||||||
|
// Old versions of High Fidelity returned invalid action ids from
|
||||||
|
// Controller.Actions.Yaw/StepYaw which were above 10000. If they are
|
||||||
|
// above 10000 then we can assume we are on an old version and hard-code
|
||||||
|
// the values. Eventually we should remove these checks.
|
||||||
|
var STEP_YAW_ACTION = Controller.Actions.StepYaw;
|
||||||
|
if (STEP_YAW_ACTION > 10000) {
|
||||||
|
STEP_YAW_ACTION = 6;
|
||||||
|
}
|
||||||
|
var SMOOTH_YAW_ACTION = Controller.Actions.Yaw;
|
||||||
|
if (SMOOTH_YAW_ACTION > 10000) {
|
||||||
|
SMOOTH_YAW_ACTION = 4;
|
||||||
|
}
|
||||||
|
|
||||||
if (action == STEP_YAW_ACTION && value != 0) {
|
if (action == STEP_YAW_ACTION && value != 0) {
|
||||||
debug("TurnAround | Got yaw action");
|
debug("TurnAround | Got step yaw action");
|
||||||
this.numTimesTurnPressed += 1;
|
++this.numTimesSnapTurnPressed;
|
||||||
|
} else if (action == SMOOTH_YAW_ACTION) {
|
||||||
|
debug("TurnAround | Got smooth yaw action");
|
||||||
|
if (this.smoothTurnDown && value === 0) {
|
||||||
|
this.smoothTurnDown = false;
|
||||||
|
++this.numTimesSmoothTurnPressed;
|
||||||
|
} else if (!this.smoothTurnDown && value !== 0) {
|
||||||
|
this.smoothTurnDown = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cleanup: function() {
|
cleanup: function() {
|
||||||
|
|
Loading…
Reference in a new issue