- Home /
Question by
defcon1 · Mar 22, 2012 at 02:21 PM ·
javascriptinstantiateinstancephyics
Prefabs instantiating at wrong spot
Hi, I am trying to make a simple astroid game, but the astroids and bullet prefabs keep instantiating at the wrong location, at 0,0,0. The astroids should move in random directions when they spawn at random locations, but they only move in 90 degrees. Here's the astroid code. Thanks.
//var spawnPoint : Transform;
var spawnAreaRange = 50;
var waitTime = 1;
var astroid : Rigidbody;
var ship : Transform;
var maxAstroids = 15;
function Start () {
Spawn();
}
function Update () {
}
function Spawn(){
for(var i = 0; i <= 15; i++){
var clone : Rigidbody;
clone = Instantiate(astroid, Vector3(Random.Range(ship.position.x,ship.position.x + 150.0),0 ,Random.Range(ship.position.z, ship.position.z + 150.0)),Quaternion.identity);
}
}
Another problem i'm having is that once the astroids instantiate, they wait 15-20 seconds to excecute any other code. Thanks in advance.
Comment
Answer by DaveA · Mar 22, 2012 at 04:48 PM
You need to add a random force to 'clone' after Instantiate