Ok so I am feeling kind of stupid right now because this is a maths thing and I should be able to think it through but it is causing me problems even after searching for a solution.
Basically I have an enemy randomly spawning in a sphere around the player, but they occasionally spawn too close.
How would I get the enemy to spawn randomly inside a sphere but also have a minimum distance from the player?
function GetRandomPosition( var minDist : float, var maxDist : float ) : Vector3 {
var out : Vector3;
while ( out == Vector3.zero ) out = Random.InsideUnitSphere();
out = out.normalized * Random.Range(minDist, maxDist);
return out;
}
...
enemyPosition = playerPosition + GetRandomPosition( 10, 20 );