- Home /
Glitch/overlapping when two objects are on exactly same transform
Is this just a shader problem or something else?
Greetings fellow devs.
I've been struggling with this same problem occasionally when I started using unity.
My current project is using a prefab maze parts (just like in the
Labyrinth board game) and they're instantiated to their certain places
when player presses keyboard button. Works like it should. :)
But when two prefabs (using box colliders,mesh,kinetic rigidbody and
standard shader) are placed to scene problem occurs with some prefabs ->
When two prefabs end to same coordinate they start clipping.
Added a gif to show what i'm typing about.
This is only happening in play mode. In editor window everything looks good. :P
Problem can be "fixed" by adding -/+0.001 to one of gameobjects current
scale and glitch is gone. But! then there's a small visible edge and i'm
trying to have smooth surface all around the maze.
So is this easily prevented by changing some player settings, setting
custom shaders to prefabs/gameobjects or do I need to micro adjust
and checking every one of them in play mode just like i've been doing to this day?
And here's pic one of prefabs just for kicks:
Answer by Eno-Khaon · Dec 18, 2020 at 11:23 PM
That is what's known as Z-fighting. It's what happens when floating point accuracy picks a fight with every pixel being rendered, and is a result of stacking multiple triangles on top of each other in that exact manner. It's also pretty commonly seen in 3D games in general.
For the most part, it's not really something that's easily solved except by ensuring that your meshes don't overlap so precisely, by whatever means are necessary. (This could include modifying the models, faking a minute depth change in the vertex shader on an arbitrary per-object basis, etc.)
So there's even a name for this phenomenon. Interesting. :)
I'm glad you could give me "Everyday you learn something new" moment.
Well looks like it's going to take a while when fixing and checking every possible prefab combination in working order.
Thank you yet again for precise answer. I'll start my prefab modifying marathon -->
Your answer
