Hey I have this game where I’m flying through some kind of matrix-cave.
(the blocky colours are just because I can’t record video properly)
In the background I have a couple big planes that are scrolling images of stalegmites and whatnot, and also I’m flowing a bunch of blue clouds to the left that are randomly infront of, and behind, the background image.
As each cloud gets to the middle of the screen, it jumps forward, then jumps back. I’m assuming it’s something to do with their distance from the camera, and maybe the camera sorts depth less accurately as things get further away? I don’t know.
I looked up “Z fighting” and I don’t think that’s what this is. The clouds instantiate on a wide Z range, and they basically all flick back n forwards.
Ok I think I’m halfway to solving this problem.I think the camera renders each object in order of distance- so the furthest away from the camera gets rendered first.
My problem with this is that
…so how do I reset the camera to render things in order of their Z position?
Yep this is a standard issue with transparent objects and the fact that objects are sorted by a single point based on distance from the camera.
As for solutions there are various possibilities
Sub-divide and split your background plane into multiple smaller planes (separate gameObjects) so that the situation you’ve identified doesn’t happen
Turn your background plane into a cube. As a cube has its origin point further back you are effectively ensuring the background is always further away than your foreground objects. However this is not a fool-proof fix, it should work here as everything stays relative to each other, but for more generalised 3d scenes it should be obvious that the exact same issue can eventually happen.
Render your background planes in a different camera, have that camera render first, then your main camera render second and with its clear flag set to none or z-buffer
There are other alternatives but they get more complex and honestly I think option 2 or 3 should work fine for you in this specific case.