Hi! I’m making a script that controls the direction and rotation of a meteor. The part that I need help on is what it does when it is hit with a bullet.
I want the asteroid to spawn 4 other asteroids, all 1/4 of its scale, after being shot with a bullet. That was easy enough. The problem is that I need to make all four little asteroids spawn in different locations around the original asteroid an not on top of each other. My script:
var Speed = 1.0;
var MinSize = 1.0;
var MaxSize = 1.0;
var asteroids : GameObject[];
var scale : float = Random.Range(MinSize,MaxSize);
function Awake(){
transform.rotation = Random.rotation;
transform.localScale = Vector3(scale,scale,scale);
}
function Update () {
transform.Translate(0,0,-Speed,Space.World);
transform.Rotate(1,1,5);
}
function OnCollisionEnter(collision : Collision){
MakeMoreThenDie(scale);
}
function MakeMoreThenDie(cheese){
[COLOR="#ff0000"]var inst1pos = Vector3((transform.up +1), transform.forward, (transform.right -1));
var inst2pos = Vector3((transform.up -1), transform.forward, (transform.right +1));
var inst3pos = Vector3((transform.up +2), transform.forward, (transform.right-2));
var inst4pos = Vector3((transform.up -2), transform.forward, (transform.right +2));[/COLOR]
var instance1 : GameObject = GameObject.Instantiate( asteroids[0],inst1pos, transform.rotation);
var instance2 : GameObject = GameObject.Instantiate( asteroids[1], inst2pos, transform.rotation);
var instance3 : GameObject = GameObject.Instantiate( asteroids[2], inst3pos, transform.rotation);
var instance4 : GameObject = GameObject.Instantiate( asteroids[3], inst4pos, transform.rotation);
cheese = cheese/4;
instance1.transform.localScale = Vector3(cheese,cheese,cheese);
instance2.transform.localScale = Vector3(cheese,cheese,cheese);
instance3.transform.localScale = Vector3(cheese,cheese,cheese);
instance4.transform.localScale = Vector3(cheese,cheese,cheese);
Destroy(gameObject);
}
The game engine does not like that I am trying to do math with the positions.
So how would I make the new asteroids all spawn close to the original one?