Search Unity

Picking up rigid bodies with two fingers

Discussion in 'Physics' started by moontoad, Dec 12, 2014.

  1. moontoad

    moontoad

    Joined:
    Dec 10, 2014
    Posts:
    4
    Ok lets say I had two fingers floating in space and a cube on a table that I wanted to pick up and hold onto. What friction coefficients would I need to use on the these rigid bodies? Right now I have it so I can grab the object but it keeps sliding out of my grasp.

    Right now I'm just doing:

    void FixedUpdate () {
    input = new Vector3(Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));
    if (rigidbody.velocity.magnitude < maxSpeed)
    {
    rigidbody.AddForce (input * moveSpeed);
    }
    }

    Then the arrow keys allow me to open and close the fingers. But what I want it to do is for the fingers to stay closed with out me having to hold the arrow key once it grabs an object.
     
  2. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    Give up on trying to do this with friction.

    Physics engines are just a model of the world, and the rigidbody dynamics in most engines are meant to model shrapnel and things bouncing around after an exploding barrel. You'd be much better off trying to simulate this with really weak breakable joints on the fingertips (maybe only adding the joints once both fingertips are in contact).

    Here's a starting point to create a joint in code between two Rigidbodies. You'll want to add breakForce and breakTorque too:

    Code (csharp):
    1.  
    2. public static ConfigurableJoint CreatePinJoint(Rigidbody from, Rigidbody to, Vector3 at)
    3. {
    4.     var joint = from.gameObject.AddComponent<ConfigurableJoint>();
    5.        
    6.     joint.connectedBody = to;
    7.     joint.anchor = from.transform.InverseTransformPoint(at);
    8.        
    9.     joint.xMotion = ConfigurableJointMotion.Locked;
    10.     joint.yMotion = ConfigurableJointMotion.Locked;
    11.     joint.zMotion = ConfigurableJointMotion.Locked;
    12.        
    13.     joint.angularXMotion = ConfigurableJointMotion.Locked;
    14.     joint.angularYMotion = ConfigurableJointMotion.Locked;
    15.     joint.angularZMotion = ConfigurableJointMotion.Locked;
    16.        
    17.     joint.configuredInWorldSpace = false;
    18.    
    19.     return joint;
    20. }
    21.  
     
    Nanako likes this.