Random Spawn zone

Hi everybody ! I’m working on a system of spawn for my monster .
I would like to create a "zone " , and instanciate randomly my monster in this zone .

But i don’t know how can i define this zone , and how to spawn my monster randomly in this zone :confused:

If someone can help me i’ll really appreaciate !

Have a good day ! :slight_smile:

You can define the spawn zone using a trigger collider. Then use the min and max bounds of this collider to select a random point.

Vector3 randomPosition = new Vector3 (Random.Range (spawnZone.bounds.min.x, spawnZone.bounds.max.x), 1, Random.Range (spawnZone.bounds.min.z, spawnZone.bounds.max.z));
1 Like

Oh great ! Thx! ( English is difficult for me ^^)

“spawnZone.bounds.min.x” will automaticly take the minim position of the zone ? or i have to set it ?

It will do it automatically. Check out Bounds for more info.

Oh i see! Thx for you’re help !
Have a good day ! :slight_smile: