# Spawn Within Circular Band

Hi,

I’m unsure how to go about this, perhaps you guys can point me in the right direction.

Basically, what I’m looking to do is spawn a bunch of asteroids randomly in a circular band with an adjustable max/min radius.

Easy enough doing it along say, the X and Z axis as I just gotta check if it’s within Xmin and Xmax or radiusMin/Max along said axis and then add/sub a random number between 0 and 25 for some height variance, but going in the circle is different, and I need some help.

There is the node ‘get vector length’, you could generate random spawn locations based on it being in a square, and then just subtract the location with the middle of the circle location (and plug the result into ‘Get Vector Length’), and if it is greater than the circle’s radius, find a new location.

That’s relying on a lot of luck seeing as the square would be rather big and the asteroids are fairly small, could make the times generation times terrible and I don’t really fancy sitting for several minutes for it to get it right as there will be a lot of em. And to do that every time something changes (in the editor).

It’s worth a try, though, perhaps it won’t be too bad.

What comes to mind would be making a vector along the x axis say, which definitely falls in your band (maybe using ‘random float in range’ with your min and max values). Then you could rotate that vector by a random number of degrees between 0 and 360 (although that might be doubling up the intial position since 0 and 360 give you the same position) to get somewhere random along the band.

I managed to get something working, rather nicely too I think.
Basically, what I do is rotate a vector whose length is 1 to a random value between 0 and 360. Then I multiply that by a random number between the min and max radius, and add a random min and max height to the Z axis.

Now my main problem is performance

The range should be 0-360 in your case, ofc.

Why 360 rather than 359? 360 would be a duplicate possibility in case of 0 being a possibility.