Instantiate new third person controller at the exact point first third person controller is destroyed

Hallo,
In my game my third person controller is destroyed when he hits a box collider, and a new one instantiated in his place.

At the moment the prefab is instantiated in the middle of the box collider, but I was wondering if there is a way of instantiating the new third person controller at the exact point the first third person controller is destroyed?

This is the script I’m using to instantiate my new third person controller (JavaScript):

#pragma strict

var prefab : GameObject;
var script : SwitchCharacters;
var vincentCamera : GameObject;

var playerGO : GameObject;  //Should be filled with the GameObject the SwitchCharacters script is attached to


private var hasPlayed = false;


function OnTriggerEnter () {

var pos : Vector3; 

if (!hasPlayed){

var newprefab = Instantiate (prefab);
var cameraofnewPrefab = Instantiate(vincentCamera);


script = playerGO.GetComponent(SwitchCharacters);
script.player02 = newprefab;
script.cam02 = cameraofnewPrefab; 

hasPlayed = true;

}

}

I found a lot on the forums about adding Instantiate(prefab, Vector3(0,0,0),Quaternion.identity); but I can’t work out how to instantiate the character at the exact point where the first character was destroyed.

Any ideas?

Thanks, Laurien

You need to get the position of the first character before you destroy it by storing it in a varaible. Then when you instantiate your new prefab, you pass in that Vector:

Instantiate(prefab, firstCharacterPosition, Quaternion.identity);