- Home /
Question by
SpeedTutor · Aug 21, 2013 at 08:19 PM ·
javascriptinstantiate
Instantiate an object next to the player?
I'm trying to Instantiate an object near to the player if at all possible, can anyone shed some light on this?
Could I use:
var player : Transform; ? Then add that to the vector3 somehow?
var object : Transform;
function CreateObject()
{
Instantiate (prefab, Vector3(0, 0, 0), Quaternion.identity);
}
Comment
Answer by Stopsecret · Aug 21, 2013 at 08:21 PM
That creates an object at the origin, replace Vector3(0, 0, 0) with something like player.transform.position + Vector3(4, 1, 0) as long as you replace prefab with object.
Answer by yeagz7 · Aug 21, 2013 at 08:22 PM
You need to instantiate the object with the position of the player's Transform. Currently you are creating it at the world zero (0, 0, 0). Try this.
var player : Transform;
var object : Transform;
function CreateObject()
{
Instantiate(prefab, player.position, Quaternion.identity);
}
Your answer
