From 53623f7583b1ef4365dd0e8f33b65e1c29683be2 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 28 Sep 2016 15:59:54 -0700 Subject: [PATCH] Make teleport.js normal rejection more lenient --- scripts/system/away.js | 21 ++++++++++++++++++++- scripts/system/controllers/teleport.js | 10 ++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/scripts/system/away.js b/scripts/system/away.js index 716fe1340e..c704da83f4 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -142,6 +142,7 @@ function ifAvatarMovedGoActive() { } // MAIN CONTROL +var isEnabled = true; var wasMuted, isAway; var wasOverlaysVisible = Menu.isOptionChecked("Overlays"); var eventMappingName = "io.highfidelity.away"; // goActive on hand controller button events, too. @@ -159,7 +160,7 @@ function safeGetHMDMounted() { var wasHmdMounted = safeGetHMDMounted(); function goAway() { - if (isAway) { + if (!isEnabled || isAway) { return; } @@ -274,6 +275,24 @@ function maybeGoAway() { } } +function setEnabled(value) { + print("setting away enabled: ", value); + if (!value) { + goActive(); + } + isEnabled = value; +} + +var CHANNEL_AWAY_ENABLE = "Hifi-Away-Enable"; +var handleMessage = function(channel, message, sender) { + print("Got away message"); + if (channel == CHANNEL_AWAY_ENABLE) { + setEnabled(message == 'enable'); + } +} +Messages.subscribe(CHANNEL_AWAY_ENABLE); +Messages.messageReceived.connect(handleMessage); + Script.update.connect(maybeMoveOverlay); Script.update.connect(maybeGoAway); diff --git a/scripts/system/controllers/teleport.js b/scripts/system/controllers/teleport.js index af3f6b0800..a0159e06a5 100644 --- a/scripts/system/controllers/teleport.js +++ b/scripts/system/controllers/teleport.js @@ -627,11 +627,17 @@ function isMoving() { } }; +// When determininig whether you can teleport to a location, the normal of the +// point that is being intersected with is looked at. If this normal is more +// than MAX_ANGLE_FROM_UP_TO_TELEPORT degrees from <0, 1, 0> (straight up), then +// you can't teleport there. +var MAX_ANGLE_FROM_UP_TO_TELEPORT = 70; function isTooCloseToTeleport(position, surfaceNormal) { var adj = Math.sqrt(surfaceNormal.x * surfaceNormal.x + surfaceNormal.z * surfaceNormal.z); var angleUp = Math.atan2(surfaceNormal.y, adj) * (180 / Math.PI); - //print(angleUp); - return angleUp < 80 || angleUp > 110 || Vec3.distance(MyAvatar.position, position) <= TELEPORT_CANCEL_RANGE; + return angleUp < (90 - MAX_ANGLE_FROM_UP_TO_TELEPORT) || + angleUp > (90 + MAX_ANGLE_FROM_UP_TO_TELEPORT) || + Vec3.distance(MyAvatar.position, position) <= TELEPORT_CANCEL_RANGE; }; function registerMappings() {