- Home /
Only show GameObject if at least 1 pixel is rendered
Hello Community,
I'm making a game where the player drives a car through a city. The problem is that the city should be very large (otherwise it would be boring). It would be very performance intense if the whole city would be active at once, so I have to destroy buildings when they're not visible to the player and instantiate them when they're visible again.
Please note:
The active objects should not be just any buildings in a specific radius because there are buildings close to the player and are not visible because there are other buildings in front of them - and there are buildings very far from the player that should be rendered.
Buildings taller than the ones in front of them should be rendered if they would be seen by the player. (blue in the picture)
All in all: How can I just render objects of which at least 1 pixel would be rendered?
Possible solutions:
Raycast to the point where the top of each building would be and look if there is an object in front of them - starting from the nearest buildings (which would be very performance intense since it would have to be done every frame or at least multiple times per second)
Please help me find better solutions ;)
Thanks in advance, Sebastian
look at this answer.
also if do end up raycasting, what would be the purpose in every frame? why not do your checks less often like every second? at least with distant buildings.
Check out this OcclusionCulling and to further disable/enable components check out OnBecameVisible/ OnBecameInvisible if i remember correctly. Cheers.
Your answer
Follow this Question
Related Questions
Is object at least partly visible? 1 Answer
Camera Zoom in&out 2 Answers
Raycast based on crosshair on screen 1 Answer
Raycast and First Person Controller 2 Answers