Skip to content

Commit 65f600e

Browse files
committed
fix(Pointer): update pointer position in fixed update
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.
1 parent aac394e commit 65f600e

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Assets/VRTK/Documentation/API.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9354,6 +9354,7 @@ Changes one game object's transform to follow another game object's transform.
93549354
### Class Variables
93559355

93569356
* `public enum FollowMoment` - The moment at which to follow.
9357+
* `OnFixedUpdate` - Follow in the FixedUpdate method.
93579358
* `OnUpdate` - Follow in the Update method.
93589359
* `OnLateUpdate` - Follow in the LateUpdate method.
93599360
* `OnPreRender` - Follow in the OnPreRender method. (This script doesn't have to be attached to a camera).

Assets/VRTK/Source/Scripts/Pointers/PointerRenderers/VRTK_BasePointerRenderer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ protected virtual void CreatePointerOriginTransformFollow()
578578
pointerOriginTransformFollowGameObject = new GameObject(VRTK_SharedMethods.GenerateVRTKObjectName(true, gameObject.name, "BasePointerRenderer_Origin_Smoothed"));
579579
pointerOriginTransformFollow = pointerOriginTransformFollowGameObject.AddComponent<VRTK_TransformFollow>();
580580
pointerOriginTransformFollow.enabled = false;
581+
pointerOriginTransformFollow.moment = VRTK_TransformFollow.FollowMoment.OnFixedUpdate;
581582
pointerOriginTransformFollow.followsScale = false;
582583
}
583584

Assets/VRTK/Source/Scripts/Utilities/ObjectFollow/VRTK_TransformFollow.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public class VRTK_TransformFollow : VRTK_ObjectFollow
1414
/// </summary>
1515
public enum FollowMoment
1616
{
17+
/// <summary>
18+
/// Follow in the FixedUpdate method.
19+
/// </summary>
20+
OnFixedUpdate,
1721
/// <summary>
1822
/// Follow in the Update method.
1923
/// </summary>
@@ -105,6 +109,14 @@ protected virtual void OnDisable()
105109
Camera.onPreCull -= OnCamPreCull;
106110
}
107111

112+
protected void FixedUpdate()
113+
{
114+
if (moment == FollowMoment.OnFixedUpdate)
115+
{
116+
Follow();
117+
}
118+
}
119+
108120
protected void Update()
109121
{
110122
if (moment == FollowMoment.OnUpdate)

0 commit comments

Comments
 (0)