Reputation: 15
as the image below shows, I would like to find a random position within the blue area (B) and not the red area (A). How can I achieve this? A and B are currently 2 colliders. I just need a position within B but it cant be within A. Thanks in advance.
Upvotes: 1
Views: 3559
Reputation: 190
One Solution is same as Nico Schertler has mentioned in the comment
if(Random.value < GetRatio(xminBlue-xminRed),xmaxRed-xmaxBlue){
x= Random.Range(xminBlue,xminRed);
}else
{
x= Random.Range(xmaxRed,xmaxBlue);
}
float GetRatio (float distance_1,float distance_2){
return distance_1 / distance_1 + distance_2;
}
In this solution u dont need to reject any coordinate
Upvotes: 2