Skip to content

Commit

Permalink
fix(Teleport): ensure position change over tiny distance change
Browse files Browse the repository at this point in the history
Previously, if the target position was very small then the lerp time
would be bigger than the elapsed time meaning the lerp would never
have a second pass and therefore the position was never updated.

This fix checks to see if the current position is not equal to the
target position after the lerp time has finished and if they're not
then it force moves the transform position to the target location.
  • Loading branch information
thestonefox committed Sep 9, 2016
1 parent e69200c commit de6358c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Assets/VRTK/Scripts/VRTK_DashTeleport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private IEnumerator lerpToPosition(Vector3 targetPosition, Transform target)
}
else
{
lerpTime = (1 / minSpeedMps) * maxDistance; // clamped to speed for small dashes
lerpTime = (1f / minSpeedMps) * maxDistance; // clamped to speed for small dashes
}

Vector3 startPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z);
Expand All @@ -134,6 +134,10 @@ private IEnumerator lerpToPosition(Vector3 targetPosition, Transform target)
t = elapsedTime / lerpTime;
if (t > 1)
{
if (transform.position != targetPosition)
{
transform.position = targetPosition;
}
t = 1;
}
yield return new WaitForEndOfFrame();
Expand Down

0 comments on commit de6358c

Please sign in to comment.