r/Unity3D•
milotoad

Picking up rigid bodies with two fingers

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.

Posted Dec 12, 2014, 4:27 PM UTC · edited

45
db_mew•

Like jonhykrazy said, joints might be a good idea. If you want infinite friction, you could just place a fixed joint at the point you touch connecting the finger and the object. I use that method for my grappling hook in my game and it seems to work quite well.

            Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
            if (Physics.Raycast(ray, out hit, 10, layerMask.value)) {
                if (hit.rigidbody != null && hit.distance < 10) {
                    oldmass = hit.rigidbody.mass;
                    hit.rigidbody.mass = 5f;
                    obj_ggun.gameObject.SetActive(true);
                    obj_ggun.transform.position = hit.point;
                    fjoint.connectedBody = hit.rigidbody;
                }
            }

That's my code for attaching the "hook" if you will, of the gravity gun on the object I want to grab, I then apply a force on that hook to move towards a "zero point" in the air in front of my player.

What you could do is give both of the fingers a fixed joint and when a finger touches an object, it attaches the joint to the point on the rigidbody it touches.

Let me know if you get anywhere with that.

Also, if you plan on moving those attached fingers with addForce, high drag values are your friend. Was able to stabilize my gravity gun really well like that, to the extent that you can throw stuff with it by flicking, but it still moves really smoothly.

2
ArchimagusExpert•

Create a Physics material with a high friction and low bounciness setting and apply it to the fingers and cube.

1
milotoadOP•

Yeah I tried 100 on both static and dynamic friction but its still sliding

mass of cube is 0.1

2
jonhykrazy•

Joints?

1
Bickooo•

Fudge it? Detect if there's currently collision between the two and just increase the drag.

1