x


Attaching a Hinge Joint upon colliding with a rigidbody.

I'm trying to create a script that will attach rigidbodies together via hinge joint based on anything that collides with them that also has the tag of "piece". I'm having trouble figuring out how to define the hingeJoint.connectedBody so that it assigns what it collided with as the connected Body.

    function OnCollisionEnter(other : Collision){

   if (other.gameObject.tag == "piece") {
        Debug.Log("Collided");
        gameObject.AddComponent(HingeJoint);
            var otherBody = other.gameObject.Rigidbody;
            hingeJoint.breakForce = 45;
            hingeJoint.breakTorque = 45;
            hingeJoint.connectedBody = otherBody;
        }
}

When playing this scene all of the objects that have this script attached to them do indeed create Hinge Joints. But not with a breakForce/Torque of 45 nor are they connected to what they collided with. I've given up trying to figure this out on my own, I need help! Any thoughts?

more ▼

asked Aug 01 '10 at 09:14 AM

Kyle 5 gravatar image

Kyle 5
28 4 4 6

Do both objects have rigid bodies? Have you tried attaching the joint to the "piece" instead of the main object? I think you are trying to assign multiple joints to one object, hence it not working properly.

Aug 01 '10 at 09:52 AM spinaljack
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I think you should change Rigidbody to rigidbody function OnCollisionEnter(other : Collision){

if (other.gameObject.tag == "piece") { Debug.Log("Collided"); gameObject.AddComponent(HingeJoint); var otherBody = other.gameObject.rigidbody; hingeJoint.breakForce = 45; hingeJoint.breakTorque = 45; hingeJoint.connectedBody = otherBody; } }

more ▼

answered Jul 05 '12 at 06:52 AM

phamvanhung2e123 gravatar image

phamvanhung2e123
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2584
x154
x145
x72
x38

asked: Aug 01 '10 at 09:14 AM

Seen: 3109 times

Last Updated: Jul 05 '12 at 06:52 AM