Hi, I can't figure out how to get the clones of a prefab to instantiate on the position of the empty game object that this script is on. All the objects that spawn come from the world space of 0,0,0. I want them to spawn FROM 0,0,0 of the LOCAL objects spot. (ie. When I move the parent object, the spawning of the cloned prefabs will follow.) Here is my code I'm using.
var prefab : Rigidbody;
var speed = 5;
var numberOfObjects = 20;
var radius = 5;
function LaunchingProjectile()
{
for (i = 0; i < numberOfObjects; i++)
{
var angle = i * Mathf.PI * 2 / numberOfObjects;
var pos = Vector3 (Mathf.Cos(angle), 0, Mathf.Sin(angle)) * radius;
clone = Instantiate(prefab, pos, Quaternion.identity);
clone.velocity = transform.TransformDirection( Vector3 (0, 1, speed));
Destroy (clone.gameObject, 3);
}
for (i = 0; i < numberOfObjects; i++)
{
angle = i * Mathf.PI * 2 / numberOfObjects;
pos = Vector3 (Mathf.Cos(angle), 0, Mathf.Sin(angle)) * radius;
clone = Instantiate(prefab, pos, Quaternion.identity);
clone.velocity = transform.TransformDirection( Vector3 (1, 0, speed));
Destroy (clone.gameObject, 3);
}
}
function Update()
{
if(Input.GetButtonDown("Fire1"))
{
LaunchingProjectile();
}
}
=====Old code above. Newer code below=========
var prefab : Rigidbody;//instantiated prefab for clone
var speed = 15;//speed that clones travel
var numberOfObjects = 15;//Used in Mathf calculation
var radius = 1;//used in MathF calculation
function Update()
{
if(Input.GetButtonDown("Fire1"))
{
LaunchingProjectile();
}
}
function LaunchingProjectile()
{
for (i = 0; i < numberOfObjects; i++)
{
var angle = i * Mathf.PI * 2 / numberOfObjects;
var position = Vector3 (Mathf.Cos(angle), 0, Mathf.Sin(angle)) * radius;
clone = Instantiate(prefab, position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 1, speed));
clone.transform.parent = transform;
Destroy (clone.gameObject, 3);
}
}