Hey everyone anyone know how to keep randomly instantiated objects from spawning on top of other objects like walls or previously spawned objects.
here's the random spawn script:
var floorHeight = -0.8f;// y axiss
var xAxis;
var zAxis;
var mine : GameObject;
static var spawn = 0;
var target : MoveToGround;
function Update () {
while (spawn <= 10)
{
var xAxis = Random.Range(-18,18);
var zAxis = Random.Range(-17,21);
//print(zAxis);
Instantiate(mine, Vector3(xAxis, floorHeight,zAxis), Quaternion.identity);
target.toGround = true;
spawn++;
}
}
So basically oncollision with the off limits part delete the object and subtract 1 from spawn?(spawn is the number of objects tht will b instantiated)
– anon90502796Depending on your set up, that would be a solution. Of course there are many implementations to many solutions though.
– anon40032747Yup works great. Thank you very much. Now would I be able to do the same to keep objects a certain distance away. Like adding a sphere collider around the object and if another object is inside it deletes and adds back to spawn? is there an easier way?
– anon90502796You could use a sphere collider, or calculate the distance in-between objects. I recommend you also ray cast (Physics.Raycast) to make sure there isn't a wall between one player/enemy and the spawn, because if there is a wall then it doesn't matter if they're close.
– anon40032747