Skip to content

Commit

Permalink
fix(Pointer): update pointer position in fixed update
Browse files Browse the repository at this point in the history
The Straight Pointer Renderer position was being updated using the
Transform Follow script and this was defaulting to using the
OnPreRender moment to update position. This had a knock on effect
that the pointer Object Interactor position was being updated in a
Fixed Update but this meant that the Object Interactor position was
not correctly updated to the correct pointer position as the pointer
position was always slightly slower due to being on the OnPreRender
setting.

The solution is to ensure the Pointer position is updated via
FixedUpdate as well to ensure the position of the pointer is correct
for when the Object Interactor is updated in the Fixed Update routine.
  • Loading branch information
thestonefox committed Oct 26, 2017
1 parent aac394e commit 65f600e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions Assets/VRTK/Documentation/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -9354,6 +9354,7 @@ Changes one game object's transform to follow another game object's transform.
### Class Variables

* `public enum FollowMoment` - The moment at which to follow.
* `OnFixedUpdate` - Follow in the FixedUpdate method.
* `OnUpdate` - Follow in the Update method.
* `OnLateUpdate` - Follow in the LateUpdate method.
* `OnPreRender` - Follow in the OnPreRender method. (This script doesn't have to be attached to a camera).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ protected virtual void CreatePointerOriginTransformFollow()
pointerOriginTransformFollowGameObject = new GameObject(VRTK_SharedMethods.GenerateVRTKObjectName(true, gameObject.name, "BasePointerRenderer_Origin_Smoothed"));
pointerOriginTransformFollow = pointerOriginTransformFollowGameObject.AddComponent<VRTK_TransformFollow>();
pointerOriginTransformFollow.enabled = false;
pointerOriginTransformFollow.moment = VRTK_TransformFollow.FollowMoment.OnFixedUpdate;
pointerOriginTransformFollow.followsScale = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class VRTK_TransformFollow : VRTK_ObjectFollow
/// </summary>
public enum FollowMoment
{
/// <summary>
/// Follow in the FixedUpdate method.
/// </summary>
OnFixedUpdate,
/// <summary>
/// Follow in the Update method.
/// </summary>
Expand Down Expand Up @@ -105,6 +109,14 @@ protected virtual void OnDisable()
Camera.onPreCull -= OnCamPreCull;
}

protected void FixedUpdate()
{
if (moment == FollowMoment.OnFixedUpdate)
{
Follow();
}
}

protected void Update()
{
if (moment == FollowMoment.OnUpdate)
Expand Down

0 comments on commit 65f600e

Please sign in to comment.