Err, this sounds very easy. But i just cant get my head around it now.
I have an array of bounds of irregular polygons and i can see if a point is inside a polygon or not with a function call.
But how would i call it recursively until a random point is NOT inside my array of bounds?
This is supposed to work, but it does not. Any help would be appreciated
Vector2 RecursiveRandomInsidePolygon(float x, float y) {
Vector2 vec = new Vector2(x, y);
if (InPolygon(vec, walkablePolygons) !InPolygon(vec, obstructedPolygons))
return vec;
return RecursiveRandomInsidePolygon(Random.Range(0f, 10f), Random.Range(0f, 10f));
}
EDIT: Its fixed now. Thanks for your time.
I would suggest using a while loop. Or a for loop of limited size to stop infinite loops.
Yes, i put a counter to limit the number of tries to a reasonable number and if it still cant find a suitable position, it will return a default position.