Skip to content

Commit

Permalink
fix(PlayerPresence): prevent collisions when swapping grab hand
Browse files Browse the repository at this point in the history
There was an issue where if the grabbing item was swapped between
hands then the player presence collider would resume colliding with
the grabbed object.

This fix ensures the colliders are only turned back on when the
grabbed object is definitely not being grabbed any more.
  • Loading branch information
thestonefox committed Oct 15, 2016
1 parent ecc6bf2 commit 7034181
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Assets/VRTK/Scripts/VRTK_PlayerPresence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,25 @@ private void OnGrabObject(object sender, ObjectInteractEventArgs e)
{
if (e.target)
{
StopCoroutine("RestoreCollisions");
IgnoreCollisions(e.target.GetComponentsInChildren<Collider>(), true);
}
}

private void OnUngrabObject(object sender, ObjectInteractEventArgs e)
{
if (e.target && e.target.GetComponent<VRTK_InteractableObject>())
if (gameObject.activeInHierarchy)
{
IgnoreCollisions(e.target.GetComponentsInChildren<Collider>(), false);
StartCoroutine(RestoreCollisions(e.target));
}
}

private IEnumerator RestoreCollisions(GameObject obj)
{
yield return new WaitForEndOfFrame();
if (obj && obj.GetComponent<VRTK_InteractableObject>() && !obj.GetComponent<VRTK_InteractableObject>().IsGrabbed())
{
IgnoreCollisions(obj.GetComponentsInChildren<Collider>(), false);
}
}

Expand Down

1 comment on commit 7034181

@grendelbiter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're the best!

Please sign in to comment.