I suck at scripting so this took forever to figure out (1 hour-ish), but I did and now I am happy. With this you can make sticky bombs or have a hand be able to dynamically pick up stuff.
make sure the objects that are colliding with eachother have rigid body components. Then put the script on just one of the objects, for instance the sticky bomb, so that when it hits a guy it will stick to him. Cool!
//STICKY BOMB SCRIPT!!!!!!!!!
function OnCollisionEnter(collision : Collision) {
//if the collision is with a rigidbody
if (collision.rigidbody) {
//add a HingeJoint component to the gameobject that has the script
gameObject.AddComponent("HingeJoint");
//set the rigidbody that we collided with as the connected body the hinge connects to
hingeJoint.connectedBody = collision.rigidbody;
}
}
285364–10226–$stickbomb_183.js (429 Bytes)