- Home /
how to "search" for a spawn point
Currently. I set my spawn position based on some team settings loaded from my map. Afterwards, for respawns, it is moved around an area that it's in (so you respawn where you last died), in a sphere + 150 meters;
Vector3 spawnLocation = _spawnPos + (Random.insideUnitSphere * 150);
_spawnTransCache.position = spawnLocation;
_spawnTransCache is my SpawnPoint. Which is a gameobject I'm moving to a location before I get spawned there. It contains a capsule collider as a sphere, who's size I set based on how big I need it.
So I'm halfway to what I want to do. Basically, I want to use a trigger that is on this object, to make sure nobody is where you're going to spawn. I know I can detect if anything is in it with TriggerOnStay, and if something is set it to not be able to spawn there. But then my problem is, well, you have to spawn somewhere right? So I need it to run those 2 lines again. Until It gets a suitable spawnLocation.
I'm hitting these 2 lines in an IEnumerator. So until it has a location, it has to not complete the enum. There isn't too much going on inside this enum, and it only lasts about 3 seconds. And I'm tired of being able to spawn inside of someone else.
Sounds like a design problem. One part is "how to check nothing is within a sphere." You can look up things like that (unless that isn't the problem.)
The rest is how to best search for a nearby spot, which depends on how you want your game to work (is any random spot within 150$$anonymous$$ fine, or is closer better? etc... .)