From 6c206d4fc5d13476be64ff2c7e54af68d3df71aa Mon Sep 17 00:00:00 2001 From: Harvey Ball Date: Sat, 15 Jul 2017 17:55:15 +0100 Subject: [PATCH] fix(Locomotion): apply headset compensation to force teleport The ForceTeleport method within the Teleport script was not applying the headset compensation upon teleport. This fix ensures the headset compensation code is applied accordingly. --- .../Scripts/Locomotion/VRTK_BasicTeleport.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Assets/VRTK/Scripts/Locomotion/VRTK_BasicTeleport.cs b/Assets/VRTK/Scripts/Locomotion/VRTK_BasicTeleport.cs index 0f177198e..d85f69f70 100644 --- a/Assets/VRTK/Scripts/Locomotion/VRTK_BasicTeleport.cs +++ b/Assets/VRTK/Scripts/Locomotion/VRTK_BasicTeleport.cs @@ -163,13 +163,14 @@ public virtual void ForceTeleport(Vector3 destinationPosition, Quaternion? desti DestinationMarkerEventArgs teleportArgs = BuildTeleportArgs(null, destinationPosition, destinationRotation); StartTeleport(this, teleportArgs); Quaternion updatedRotation = SetNewRotation(destinationRotation); - CalculateBlinkDelay(blinkTransitionSpeed, destinationPosition); + Vector3 finalDestination = GetCompensatedPosition(destinationPosition, destinationPosition); + CalculateBlinkDelay(blinkTransitionSpeed, finalDestination); Blink(blinkTransitionSpeed); if (ValidRigObjects()) { - playArea.position = destinationPosition; + playArea.position = finalDestination; } - ProcessOrientation(this, teleportArgs, destinationPosition, updatedRotation); + ProcessOrientation(this, teleportArgs, finalDestination, updatedRotation); EndTeleport(this, teleportArgs); } @@ -302,15 +303,20 @@ protected virtual Vector3 GetNewPosition(Vector3 tipPosition, Transform target, return tipPosition; } + return GetCompensatedPosition(tipPosition, playArea.position); + } + + protected virtual Vector3 GetCompensatedPosition(Vector3 givenPosition, Vector3 defaultPosition) + { float newX = 0f; float newY = 0f; float newZ = 0f; if (ValidRigObjects()) { - newX = (headsetPositionCompensation ? (tipPosition.x - (headset.position.x - playArea.position.x)) : tipPosition.x); - newY = playArea.position.y; - newZ = (headsetPositionCompensation ? (tipPosition.z - (headset.position.z - playArea.position.z)) : tipPosition.z); + newX = (headsetPositionCompensation ? (givenPosition.x - (headset.position.x - playArea.position.x)) : givenPosition.x); + newY = defaultPosition.y; + newZ = (headsetPositionCompensation ? (givenPosition.z - (headset.position.z - playArea.position.z)) : givenPosition.z); } return new Vector3(newX, newY, newZ);