- Home /
Random generating
How do i make a object spawn randomly everywhere on one axis? There always needs to be some space between each of the spawn. And the objects only spawn in a short distance of you, and dissapear when it gets out of that radius.
Well i know you cant just answer that here, but do anyone know any tutorials for this? I can't find any.
Answer by wibble82 · Feb 10, 2014 at 03:36 PM
I don't know of any tutorials this specific. To answer a few of your questions:
To randomly spawn objects along a given axis, use the unity 'Random.Range(min,max)' function. It will give you a random number between min and max, that you can then use to position an object you instantiate.
The minimum spacing issue can be a tricky one. The simplest approach is to simply to get your random number, work out the random position you'll use, and check if there's anything too close. If there isn't, go ahead and instantiate your object. If there is, either don't spawn or pick another random number.
To make things disapear outside of a short distance of you, give them a script that in the fixed update function says 'if player is farther away thax x, destroy me'!
Your answer
Follow this Question
Related Questions
Procedural Generation 2 Answers
Repeating map generation 0 Answers
Spawn object from Random Vector3 in array 0 Answers
Endless/infinite runner random enemy spawning multi lane 1 Answer
How to randomly replace the main platform with additional ones? 0 Answers