# Choose a random position in a city

I’ve created a city, with horizontal and vertical streets (pic below). On all the buildings I attached a box collider, and now I want to create an “endpoint” randomly, so when the player reaches that point, the game will end.

[20085-screenshot+2014-01-02+13.16.17.png|20085]

I can create a random point, but the problem is that the point may be laying at the same position as a building, so the player can’t access the path to the point.

Is there a way to dynamically predict that the point is under a building (collider?)? I’m developing for a mobile device.

Thanks!

I think there are several possibilities to achieve that.

The one which is most generic (not necessarily the most easy) I would guess would be to register all buildings in a list. Then when you generate the random point you could loop through that list, and calculate - using the buildings transform.position and transform.localScale - whether the point you generated lies within the range of any of the buildings. If it does, generate a new point - check it again, if not, exit the algorithm, because a valid point is found.

RandomPoint;

``````if(physics.CheckSphere(RandomPoint,.1f)
FindPoint();

else
EndPoint = RandomPoint;
``````

mark as answered and have a nice day!
dont forget to set it up at some point to only cast against building colliders by placing them in a special layer so that later on players and cars etc dont cause it to set a new point