- Home /
instantiated object not in right position
im trying to instantiate an object above my player (currently a cube) im using
temp = Instantiate(carry,transform.position + new Vector3(0,5,0),transform.rotation) as Rigidbody;
this works ok, but the instantiated object is always a few units to the left of the player. if I set the players position to 0,0,0 in the editor then press play, the inspector shows it to be -8,0,0.
bit confused here, both objects have rigidbody components attached, could it be something to do with that? or some localposition thing?
thanks in advance
Are you sure you don't have another script that is positionning your player?
at work now, will check when I get back, thanks. pretty sure its just physics controlling it though.
Be sure both your player and your prefab are centered to their parents' positions.
well, I couldn't work out how to change the centre of objects, but I cheated and made a blank gameobject and parented all the other bits to that, and put that in the centre, works ok, maybe theres some kind of tradeoff but currently, its doing the job, thanks for the pointers guys :)
Answer by BuildIntoGames · Aug 22, 2013 at 05:51 PM
var temp : GameObject;
var positionBlock : GameObject;
function Start () {
temp = Instantiate(carry, positionBlock.transform.position ,positionBlock.transform.rotation);
}
I'm not too sure this is what you want. Attach this script to an empty game object. Make the variable temp as the object you would like to clone. Create another game object and move it to where you want your clone to spawn. Then, make that block the variable positionBlock. On start, it will clone your object and put it in the position of the positionBlock.
Your answer
![](https://koobas.hobune.stream/wayback/20220613112555im_/https://answers.unity.com/themes/thub/images/avi.jpg)