I’m making a fps game. When you look around the environment, your gun model can clip into the geometry and it looks really bad. I’ve tried two solutions to this:
Make the gun’s materials renderqueue 2010
In the materials shader put “Ztest Always”.
Though this does solve my problem, it make the model look really strange. Almost transparent. Because some of the faces of the model that are facing the camera but would normally be obscured by other geometry, now gets rendered and show through.
Is there something else i can do to avoid the gun clipping?
Yeah, a common solution is to use multiple cameras with different depth values. Like, your game world camera could be depth 0 and your gun camera could be 1. As a side benefit, the cameras can have different near and far planes, which can be useful.
You’d set your gun camera’s clear flags to “Depth” to let the first camera’s image through.
There are several threads on first person weapons on the forum. Search for those. They describe several ways to solve this along with the potential issues they have.
I have struggled with this myself. I tried the multiple camera approach, but then ran into issues with post processing. What I ended up doing is made the scale of the model very small. And placed it as close to the near clipping plane as possible. The near clipping plane is kept inside the character controller’s capsule collider. Therefore, the model can never clip into nearby geometry.
The cons of this is how it receives realtime lights and shadows. It may not receive correct shadows due to the scale of the item. So the other solution is to have scene lights ignore this item on the layer, and have the item be illuminated by a separate dedicated light.
I used the standard shader with ZTest Always approach instead only for transparent items. But it requires multiple materials with assigned render queues so Unity can handle the depth properly (which can be a nightmare in itself)