Hi all,
I understand that there's a Random.insideUnitCircle variable to get a random 2D coordinate inside a theoretical circle.
But what if I wanted to get a random 2D coordinate outside of that theoretical circle? Any ideas on how to go about that?
Thanks in advance,
Dendro
system
2
Broadly, this is what I would do:
-
Randomise a position within the
min/max bounds
- Check distance from the centrepoint
to the randomised position
- If it's less than a desired radius,
recalculate the random position
Be aware that sqrMagnitude is much faster than Vector2.magnitude. To use this, you will then obviously need to square the radius value. For example:
if ( (randomPos.position - centrePoint.position).sqrMagnitude <= radius*radius )
{ // retry }