Skip to content

Commit

Permalink
fix(Locomotion): apply headset compensation to force teleport
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thestonefox committed Jul 15, 2017
1 parent 7aee0d6 commit 6c206d4
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Assets/VRTK/Scripts/Locomotion/VRTK_BasicTeleport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6c206d4

Please sign in to comment.