Skip to content

Commit ffa49fe

Browse files
committed
fix(Pointers): ensure object interactor is set by global scale
The pointer object interactor that becomes an extension of the controller but tracks the scale of the actual pointer cursor. This would cause an issue when the camera rig was scaled, the object interactor would change size along with the camera rig and no longer match the scale of the pointer cursor. This fix uses the global scale of the pointer cursor to set the global scale of the object interactor so the scales continue to match even when the camera rig is scaled.
1 parent e6b4d15 commit ffa49fe

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,15 @@ protected virtual void CreateObjectInteractor()
504504
VRTK_PlayerObject.SetPlayerObject(objectInteractorAttachPoint, VRTK_PlayerObject.ObjectTypes.Pointer);
505505
}
506506

507-
ScaleObjectInteractor(Vector3.one * 0.025f);
507+
ScaleObjectInteractor(Vector3.one);
508508
objectInteractor.SetActive(false);
509509
}
510510

511511
protected virtual void ScaleObjectInteractor(Vector3 scaleAmount)
512512
{
513513
if (objectInteractor != null)
514514
{
515-
objectInteractor.transform.localScale = scaleAmount;
515+
VRTK_SharedMethods.SetGlobalScale(transform, scaleAmount);
516516
}
517517
}
518518

Assets/VRTK/Scripts/Pointers/PointerRenderers/VRTK_StraightPointerRenderer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ protected virtual void SetPointerAppearance(float tracerLength)
220220
actualContainer.transform.position = origin.position;
221221
actualContainer.transform.rotation = origin.rotation;
222222

223-
ScaleObjectInteractor(actualCursor.transform.localScale * 1.05f);
223+
float objectInteractorScaleIncrease = 1.05f;
224+
ScaleObjectInteractor(actualCursor.transform.lossyScale * objectInteractorScaleIncrease);
224225

225226
if (destinationHit.transform)
226227
{

Assets/VRTK/Scripts/Utilities/VRTK_SharedMethods.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,17 @@ public static float NumberPercent(float value, float percent)
445445
return (percent == 0f ? value : (value - (percent / 100f)));
446446
}
447447

448+
/// <summary>
449+
/// The SetGlobalScale method is used to set a transform scale based on a global scale instead of a local scale.
450+
/// </summary>
451+
/// <param name="transform">The reference to the transform to scale.</param>
452+
/// <param name="globalScale">A Vector3 of a global scale to apply to the given transform.</param>
453+
public static void SetGlobalScale(this Transform transform, Vector3 globalScale)
454+
{
455+
transform.localScale = Vector3.one;
456+
transform.localScale = new Vector3(globalScale.x / transform.lossyScale.x, globalScale.y / transform.lossyScale.y, globalScale.z / transform.lossyScale.z);
457+
}
458+
448459
#if UNITY_EDITOR
449460
public static BuildTargetGroup[] GetValidBuildTargetGroups()
450461
{

DOCUMENTATION.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6665,6 +6665,18 @@ The Vector2ShallowCompare method compares two given Vector2 objects based on the
66656665

66666666
The NumberPercent method is used to determine the percentage of a given value.
66676667

6668+
#### SetGlobalScale/2
6669+
6670+
> `public static void SetGlobalScale(this Transform transform, Vector3 globalScale)`
6671+
6672+
* Parameters
6673+
* `this Transform transform` - The reference to the transform to scale.
6674+
* `Vector3 globalScale` - A Vector3 of a global scale to apply to the given transform.
6675+
* Returns
6676+
* _none_
6677+
6678+
The SetGlobalScale method is used to set a transform scale based on a global scale instead of a local scale.
6679+
66686680
---
66696681

66706682
## Policy List (VRTK_PolicyList)

0 commit comments

Comments
 (0)