From 5ed3ccf661a819d3816d08b5e7fcfc8167335aeb Mon Sep 17 00:00:00 2001 From: Harvey Ball Date: Mon, 14 Aug 2017 10:15:06 +0100 Subject: [PATCH] feat(Pointer): add direction indicator touchpad deadzone The Pointer Direction Indicator now has a `touchpad deadzone` setting that prevents the direction indicator being rotated if the touchpad is being touched within the deadzone. This is useful if the direction indicator doesn't want to be activated within a specific threshold on the touchpad (or thumbstick) axis. --- .../Scripts/VRTK_PointerDirectionIndicator.cs | 11 ++++++++++- DOCUMENTATION.md | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Assets/VRTK/Prefabs/Resources/Scripts/VRTK_PointerDirectionIndicator.cs b/Assets/VRTK/Prefabs/Resources/Scripts/VRTK_PointerDirectionIndicator.cs index 44a98c068..d3d57c569 100644 --- a/Assets/VRTK/Prefabs/Resources/Scripts/VRTK_PointerDirectionIndicator.cs +++ b/Assets/VRTK/Prefabs/Resources/Scripts/VRTK_PointerDirectionIndicator.cs @@ -30,6 +30,10 @@ public enum VisibilityState AlwaysOnWithPointerCursor } + [Header("Control Settings")] + [Tooltip("The touchpad axis needs to be above this deadzone for it to register as a valid touchpad angle.")] + public Vector2 touchpadDeadzone = Vector2.zero; + [Header("Appearance Settings")] [Tooltip("If this is checked then the reported rotation will include the offset of the headset rotation in relation to the play area.")] @@ -125,12 +129,17 @@ protected virtual void Awake() protected virtual void Update() { - if (controllerEvents != null && controllerEvents.touchpadTouched && controllerEvents.GetTouchpadAxis() != Vector2.zero) + if (controllerEvents != null && controllerEvents.touchpadTouched && !InsideDeadzone(controllerEvents.GetTouchpadAxis())) { float touchpadAngle = controllerEvents.GetTouchpadAxisAngle(); float angle = ((touchpadAngle > 180) ? touchpadAngle -= 360 : touchpadAngle) + headset.eulerAngles.y; transform.localEulerAngles = new Vector3(0f, angle, 0f); } } + + protected virtual bool InsideDeadzone(Vector2 currentAxis) + { + return (currentAxis == Vector2.zero || (Mathf.Abs(currentAxis.x) <= touchpadDeadzone.x && Mathf.Abs(currentAxis.y) <= touchpadDeadzone.y)); + } } } \ No newline at end of file diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index a3ba4c21f..1b590eb94 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -771,6 +771,7 @@ This can be useful for rotating the play area upon teleporting to face the user ### Inspector Parameters + * **Touchpad Deadzone:** The touchpad axis needs to be above this deadzone for it to register as a valid touchpad angle. * **Include Headset Offset:** If this is checked then the reported rotation will include the offset of the headset rotation in relation to the play area. * **Display On Invalid Location:** If this is checked then the direction indicator will be displayed when the location is invalid. * **Use Pointer Color:** If this is checked then the pointer valid/invalid colours will also be used to change the colour of the direction indicator.