From ef7ed7090315b6a09475a5db9f9182107eb4b5bf Mon Sep 17 00:00:00 2001 From: Toomas Tamm Date: Fri, 28 May 2021 17:04:43 +0300 Subject: [PATCH] Add patch for XR Controller state instability, teleporting and turning dont need finger to be lifted --- .../UnityXR/ActionBasedControllerManager.cs | 34 ++++++++++++++----- .../XRI Default Input Actions.inputactions | 4 +-- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Assets/Scripts/UnityXR/ActionBasedControllerManager.cs b/Assets/Scripts/UnityXR/ActionBasedControllerManager.cs index cd05e50f..ad827400 100644 --- a/Assets/Scripts/UnityXR/ActionBasedControllerManager.cs +++ b/Assets/Scripts/UnityXR/ActionBasedControllerManager.cs @@ -153,10 +153,9 @@ public class ActionBasedControllerManager : MonoBehaviour get => m_TeleportModeActivate; set => m_TeleportModeActivate = value; } - + // State transition actions - [SerializeField] - [Tooltip("The reference to the action of listening to teleport actions.")] + [SerializeField] [Tooltip("The reference to the action of listening to teleport actions.")] InputActionReference m_NagivationModifier; /// @@ -541,11 +540,20 @@ public class ActionBasedControllerManager : MonoBehaviour var cancelTeleportModeAction = GetInputAction(m_TeleportModeCancel); var allowNavigationAction = GetInputAction(m_NagivationModifier); + var triggerTeleportMode = teleportModeAction != null && teleportModeAction.IsPressed(); var cancelTeleport = cancelTeleportModeAction != null && cancelTeleportModeAction.IsPressed(); var allowNavigation = allowNavigationAction != null && allowNavigationAction.IsPressed(); - - if (triggerTeleportMode && !cancelTeleport && allowNavigation) + + #region Check if teleport vector is north + + Vector2 teleportAxis = teleportModeAction.ReadValue(); + bool isNorth = teleportAxis.y > 0.8; + + #endregion + + + if (triggerTeleportMode && !cancelTeleport && allowNavigation && isNorth) { TransitionState(m_SelectState, m_TeleportState); return; @@ -569,13 +577,23 @@ public class ActionBasedControllerManager : MonoBehaviour var cancelTeleportModeAction = GetInputAction(m_TeleportModeCancel); var allowNavigationAction = GetInputAction(m_NagivationModifier); - var cancelTeleport = cancelTeleportModeAction != null && cancelTeleportModeAction.triggered; var releasedTeleport = teleportModeAction != null && teleportModeAction.phase == InputActionPhase.Waiting; var allowNavigation = allowNavigationAction != null && allowNavigationAction.IsPressed(); - - if (cancelTeleport || releasedTeleport) + + + if (cancelTeleport || releasedTeleport || !allowNavigation) + { + if (!cancelTeleport) + { + // Force teleportation + XRRayInteractor interactor = m_TeleportControllerGameObject.GetComponent(); + if (interactor.selectTarget != null) + interactor.interactionManager.ForceSelect(interactor, interactor.selectTarget); + } + TransitionState(m_TeleportState, m_SelectState); + } } void OnUpdateInteractState() diff --git a/Assets/XR Interaction Toolkit/1.0.0-pre.1/Default Input Actions/XRI Default Input Actions.inputactions b/Assets/XR Interaction Toolkit/1.0.0-pre.1/Default Input Actions/XRI Default Input Actions.inputactions index 08c8763f..4f356872 100644 --- a/Assets/XR Interaction Toolkit/1.0.0-pre.1/Default Input Actions/XRI Default Input Actions.inputactions +++ b/Assets/XR Interaction Toolkit/1.0.0-pre.1/Default Input Actions/XRI Default Input Actions.inputactions @@ -496,9 +496,9 @@ }, { "name": "Teleport Mode Activate", - "type": "Button", + "type": "Value", "id": "a6c7231d-c55d-4dd4-9e87-877bb5522ef5", - "expectedControlType": "Button", + "expectedControlType": "Vector2", "processors": "", "interactions": "" },