Spawning gameobjects outside a radius rather than inside?

Is there a way to instnatiate gameobjects in Unity outside of a radius rather than inside? What I’m talking about is having gameobjects instantiate anywhere but the radius specified and that’s because I plan on having enemies instantiate around my player but a set distance away so that I don’t have any problems with the enemies instantiating in and killing the player immediately.

I found a unity question on this topic but I’m not 100% sure whether it’s what I’m looking for.

I’m open to checking out other methods as well, for example just being able to spawn enemies in at a set distance from the player would be nice. I know the equation I think for doing it from a set position but what I want to be able to do is have the enemy spawn at random directions.

1 Like

Conceptually, you do actually want an outer boundary for spawning, because you probably don’t want objects spawning infinitely far away. So if the furthest an object should appear is 10m, that should be part of your formula. And if you don’t want them spawning within 2m, then you want that that be part of your formula.

So you want a random number between, say, 2 and 10.

well, spawning in a radius is just checking that Distance is less than Radius, just flip it, i don’t really see the problem here

Vector3 offset = Random.OnUnitSphere * Random.Range(minRad, maxRad);?

3 Likes

… Well that was easier than I expected lol I must have been looking at stuff that was too complicated, thanks I’ll have an experiment.

We all have that problem from time to time, last month i spent a weekend trying to flip an RGB color when all i needed to do was go to HSV

1 Like

I blame that radius code I was looking at most of last week -_-