- Home /
Random box generator in certain area.
I cant get my head around this. I want to make a random box generated map,(not as in a big world of boxed stacked on top of each other). But like in the game playing with fire(look at the picture below). One layer of boxed randomly placed in a specific area. BUT i also need it to check for collision, so that it does not spawn in other things. And off cause it has to be in 3D.
The part of checking for collision is not the hard part, it's the box generator i am struggling with. It dosent matter if it is done in c# or java script. Any suggestions or tips that could help me.
.
Create an multidimensional array to store whether each point is available to spawn or not, populate/update it by each initial spawn/placement/movement.
Thanks.
Thought of using arrays, just were not sure how it worked. But i checked out a tutorial on it so i will try to figure something out.
Answer by DonDeer · Mar 06, 2014 at 03:00 PM
You could make a spawnpoint(empty gameobject) on every tile the boxes are supposed to spawn at, and then make a Random.Range(1,5) and if it is 5 then spawn box.
Exsample script (for the spawnpoints):
var spawn = 0;
var box : GameObject;
function Start ()
{
spawn = Random.Range(1,5);
}
function Update ()
{
if (spawn == 5)
Instantiate(box, gameObject.transform.position, gameObject.transform.rotation);
}
This sounds great, thanks for the help. I really appreciate it. :)
Your answer
