Instantiating Ragdolls, Objects, etc...

Hey guys, i’m trying to figure out instantiation and how it all works, so I was checking the docs, and heres the example:

var explosion : Transform;

// When a collision happens destroy ourselves
// and spawn an explosion prefab instead
function OnCollisionEnter ()
{
    Destroy (gameObject);

    var theClonedExplosion : Transform;
    theClonedExplosion = Instantiate(explosion,
            transform.position, transform.rotation);
}

Now i’m trying to make a ragdoll appear when an NPC des, in his place with his positioning, etc. I would like to know if i have this correct because I cant seem to get it to work… var explosion would be an undefined transform and var theClonedExplosion would be my RagDoll, wait I think I see my problem, both variables would be my ragdoll’s transforms, and it would make an instance named explosion, but what about the transform.pos and transform.rot, where does it get that from, the gameObject the script is attached to? I’m confused and reading the docs don;t help a whole lot for this very reason, they just show the syntax and tell me what it does. Obviously i know what Instantiate does or else i wouldn’t have known to look up the syntax for it, i need more of an explanation as to WHY it works the way it does, what parameters are needed, and where to put em. Any help is greatly appreciated!!!

In the FPS demo(free downlod here at unity)there is a script with ragdoll holding the original velocity and rotation. Plus all the tutorials are a goos source of scripts to get anyones script library a good start. When i figure something new out i copy the example to a text document so i can put several examples on the same text doc without the variables and code being compiled. Then you can just look it up and copy and paist what u need, when you need it (ie) Lights/all examples of things to do with lights. :smile:

Oh believe me, i’m saving all the useful scripts i come across, and believe me I do research before I come straight to the forums, but tutorials are so non-interactive, and most of the ones on the website are just like “heres a script, attach it to this guy” and I’m looking for of an explanation as to HOW the scripts work exactly. And yes, i’m doing the FPS example, and am trying to get it to copy the transforms using this code:

	static function CopyTransformsRecurse (src : Transform,  dst : Transform) {
	dst.position = src.position;
	dst.rotation = src.rotation;
	
	for (var child : Transform in dst) {
		// Match the transform with the same name
		var curSrc = src.Find(child.name);
		if (curSrc)
			CopyTransformsRecurse(curSrc, child);
	}

	
	}

But it makes my ragdoll appear crazy far away, i’m not sure why. It works fine without it, but my ragdoll starts in the T-pose facing the wrong way lol. Any ideas?

In response to your original question, I think your code was correct. It should put the explosion prefab at the position where the character was standing.

As for copying the transforms, are you doing this to try to solve the original problem or is this for something else?