- Home /
Nail a rigidbody to another
Hi,
I have two rigidbodies in my scene and I'm trying to nail them together. The nail should be placed where raycast hit.point is. I've managed to do that but when the objects are attached, they bounce around unrealistically. I think it's due to the fact that colliders are constantly touching each other. What can I do to prevent that ? (I prefer using joints than parenting)
Here's a part of my code :
...
HingeJoint joint = longCube.AddComponent<HingeJoint> ();
joint.connectedBody = hit.collider.GetComponent<Rigidbody> ();
joint.axis = hit.normal;
joint.enableCollision = true;
...
For one, I think you'll need to calculate anchor and connectedAnchor, because that's where the hinge is actually acting on (I think yours is trying to connect the centers of both objects). The other consideration could be the enableCollision flag of the joint, which would essentially ignore the collision between the two colliders.
Hmm, thanks. When I disable Collision, the bouncing is still there but I think the problem is that it connects the centers of objects as you said. I'm going to try what you suggested.