Skip to content

Commit

Permalink
fix(Interaction): prevent spring joint when other controller attached
Browse files Browse the repository at this point in the history
When an Interactable Object is grabbed, if that object has a joint on
it already causes the controller to be attached with a Spring Joint.
This causes an issue when another controller is grabbing the item
because it adds a Fixed Joint to the object causing the second grabbing
controller to have a Spring Joint added when grabbing from one hand
to the other.

The solution is to check to see if the existing joint is on a
controller and if it is then add a Fixed Joint instead.
  • Loading branch information
thestonefox committed May 13, 2016
1 parent c4a1e26 commit f8e1dac
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Assets/SteamVR_Unity_Toolkit/Scripts/SteamVR_InteractGrab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,27 @@ private void SnapObjectToGrabToController(GameObject obj)
obj.transform.position = controllerAttachPoint.transform.position;
}

if (obj.GetComponent<Joint>())
CreateJoint(obj);
}

private bool JointOnController(GameObject obj)
{
return (obj.GetComponent<Joint>() && obj.GetComponent<Joint>().connectedBody && obj.GetComponent<Joint>().connectedBody.gameObject.GetComponentInParent<SteamVR_InteractTouch>());
}

private void CreateJoint(GameObject obj)
{
if (obj.GetComponent<Joint>() && ! JointOnController(obj))
{
SpringJoint tempSpringJoint = obj.AddComponent<SpringJoint>();
tempSpringJoint.spring = 500;
tempSpringJoint.damper = 50;
controllerAttachJoint = tempSpringJoint;
} else
}
else
{
controllerAttachJoint = obj.AddComponent<FixedJoint>();
}

controllerAttachJoint.connectedBody = controllerAttachPoint;
}

Expand Down

0 comments on commit f8e1dac

Please sign in to comment.