- Home /
Question by
Lautaro-Arino · Apr 10, 2017 at 11:09 PM ·
cameraboundsworldspace
Random position in visible world space
I often toy around with 2d games. Is there a way to get the bounds of what is visible in the camera/game screen as a world space bound to be able to get a random position that is inside the visible world space?
Comment
I would say, pick a random viewport coordinate, then convert from viewport to world space, by default it would have to be a point in the camera. Then if you want to set it to the ground, you can raycast the coordinate onto your world plane.
EDIT: The alternative would be based on the cameras frustrum, and the overhead would not be worth it in a 2D game. In 3D, sure it may make since, but in a 2d or top-down game, the frustrum calculations would likely be overkill.
Your answer