Skip to content

Commit 083d026

Browse files
committed
fix(Interaction): prevent continuous rumble on touch
The touch rumble can get stuck in a loop if objects are touched in quick succession. It's better to only allow for one rumble at a time and let that rumble finish before triggering another rumble otherwise the controller could be overloaded with rumble requests.
1 parent dcb8156 commit 083d026

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_InteractTouch.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class VRTK_InteractTouch : MonoBehaviour
3535
private SteamVR_TrackedObject trackedController;
3636
private VRTK_ControllerActions controllerActions;
3737
private GameObject controllerRigidBodyObject;
38+
private bool triggerRumble;
3839

3940
public virtual void OnControllerTouchInteractableObject(ObjectInteractEventArgs e)
4041
{
@@ -111,6 +112,7 @@ private void Start()
111112
Utilities.SetPlayerObject(this.gameObject, VRTK_PlayerObject.ObjectTypes.Controller);
112113
CreateTouchCollider(this.gameObject);
113114
CreateControllerRigidBody();
115+
triggerRumble = false;
114116
}
115117

116118
private void OnTriggerEnter(Collider collider)
@@ -157,13 +159,20 @@ private void OnTriggerStay(Collider collider)
157159
}
158160

159161
var rumbleAmount = touchedObjectScript.rumbleOnTouch;
160-
if (!rumbleAmount.Equals(Vector2.zero))
162+
if (!rumbleAmount.Equals(Vector2.zero) && !triggerRumble)
161163
{
164+
triggerRumble = true;
162165
controllerActions.TriggerHapticPulse((ushort)rumbleAmount.y, rumbleAmount.x, 0.05f);
166+
Invoke("ResetTriggerRumble", rumbleAmount.x);
163167
}
164168
}
165169
}
166170

171+
private void ResetTriggerRumble()
172+
{
173+
triggerRumble = false;
174+
}
175+
167176
private bool IsColliderChildOfTouchedObject(GameObject collider)
168177
{
169178
if (touchedObject != null && collider.GetComponentInParent<VRTK_InteractableObject>() && collider.GetComponentInParent<VRTK_InteractableObject>().gameObject == touchedObject)

0 commit comments

Comments
 (0)