Skip to content

Commit f0e4570

Browse files
committed
fix(Interaction): ensure touched objects check ancestors in triggers
The touched object collider may be a child of the object that is in fact the interactable object so the collider's ancestors also need checking for the presence of an interactable object.
1 parent 9bf7506 commit f0e4570

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_InteractTouch.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,25 @@ private void Start()
115115
triggerRumble = false;
116116
}
117117

118+
private GameObject GetColliderInteractableObject(Collider collider)
119+
{
120+
GameObject found = null;
121+
if (collider.gameObject.GetComponent<VRTK_InteractableObject>())
122+
{
123+
found = collider.gameObject;
124+
}
125+
else
126+
{
127+
found = collider.gameObject.GetComponentInParent<VRTK_InteractableObject>().gameObject;
128+
}
129+
return found;
130+
}
131+
118132
private void OnTriggerEnter(Collider collider)
119133
{
120134
if (IsObjectInteractable(collider.gameObject) && (touchedObject == null || !touchedObject.GetComponent<VRTK_InteractableObject>().IsGrabbed()))
121135
{
122-
lastTouchedObject = collider.gameObject;
136+
lastTouchedObject = GetColliderInteractableObject(collider);
123137
}
124138
}
125139

@@ -132,14 +146,7 @@ private void OnTriggerStay(Collider collider)
132146

133147
if (touchedObject == null && IsObjectInteractable(collider.gameObject))
134148
{
135-
if (collider.gameObject.GetComponent<VRTK_InteractableObject>())
136-
{
137-
touchedObject = collider.gameObject;
138-
}
139-
else
140-
{
141-
touchedObject = collider.gameObject.GetComponentInParent<VRTK_InteractableObject>().gameObject;
142-
}
149+
touchedObject = GetColliderInteractableObject(collider);
143150

144151
var touchedObjectScript = touchedObject.GetComponent<VRTK_InteractableObject>();
145152

0 commit comments

Comments
 (0)