# How to avoid Z-fighting

**URL:** https://discussions.unity.com/t/how-to-avoid-z-fighting/419792
**Category:** Terrain
**Created:** [August 4, 2010, 10:35pm UTC](https://discussions.unity.com/t/how-to-avoid-z-fighting/419792 "2010-08-04T22:35:25Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![anon\_32068865](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@anon\_32068865](https://discussions.unity.com/u/anon_32068865)
#### Post date: [August 4, 2010, 10:35pm UTC](https://discussions.unity.com/t/how-to-avoid-z-fighting/419792/1 "2010-08-04T22:35:25Z")

</div>

Hello 🙂 I have my terrain water very close to each other so there is a z-fighting all the time on edges of the coast. How can I avoid it? For example to tll the terrain to be drawn always before water or sth like that?

---

<div class="post-metadata">

### Author: ![Dreamora](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/dreamora/32/91058_2.png) [@Dreamora](https://discussions.unity.com/u/Dreamora)
#### Post date: [August 4, 2010, 10:36pm UTC](https://discussions.unity.com/t/how-to-avoid-z-fighting/419792/2 "2010-08-04T22:36:33Z")

</div>

reduce the view distance, ensure that far clip plane / near clip plane is never larger than 30000

---

<div class="post-metadata">

### Author: ![anon\_32068865](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@anon\_32068865](https://discussions.unity.com/u/anon_32068865)
#### Post date: [August 4, 2010, 10:44pm UTC](https://discussions.unity.com/t/how-to-avoid-z-fighting/419792/3 "2010-08-04T22:44:40Z")

</div>

Yes… I thought about that but where can I set that for built-in FPSwalker prefab?

---

<div class="post-metadata">

### Author: ![anon\_95765487](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@anon\_95765487](https://discussions.unity.com/u/anon_95765487)
#### Post date: [August 4, 2010, 11:22pm UTC](https://discussions.unity.com/t/how-to-avoid-z-fighting/419792/4 "2010-08-04T23:22:15Z")

</div>

The values Dreamora refers to are properties of the camera. So unless the FPSWalker prefab is or includes a camera, it won’t be there, it will be on the main camera in your scene.

Remember that the key to Z-fighting is the **ratio** between the near and far planes.

For example:

Near: 0.1, Far: 1000  
Near: 0.5, Far: 1000

You’ve only offset your near plane by 0.4 world units. It’s not a huge distance. The ratio between your near and far planes just improved 5 fold, however.

So don’t just automatically crank down the far plane, as you can often get more mileage cranking _up_ the near plane. Often without much/any noticeable difference too!

Also, you should remember that the z-buffer is not linear. So you inherently get greater precision closer to the camera than you do further away. This is logical and helpful, but it makes it even more important not to needlessly set your nearplane too low or you’re wasting a huge proportion of your z-precision on things you don’t need/won’t see.

Hope that helps.

---

<div class="post-metadata">

### Author: ![anon\_32068865](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@anon\_32068865](https://discussions.unity.com/u/anon_32068865)
#### Post date: [August 5, 2010, 8:11pm UTC](https://discussions.unity.com/t/how-to-avoid-z-fighting/419792/5 "2010-08-05T20:11:58Z")

</div>

Ok… so I’ve added a Camera component to the built-in FPS walker prefab and now I can’t move mouse vertical… Why that happened?

---

<div class="post-metadata">

### Author: ![anon\_95765487](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@anon\_95765487](https://discussions.unity.com/u/anon_95765487)
#### Post date: [August 5, 2010, 9:05pm UTC](https://discussions.unity.com/t/how-to-avoid-z-fighting/419792/6 "2010-08-05T21:05:33Z")

</div>

I didn’t suggest adding a camera component. Your camera should be a separate gameobject.

---

<div class="post-metadata">

### Author: ![anon\_75875665](https://avatars.discourse-cdn.com/v4/letter/a/8491ac/32.png) [@anon\_75875665](https://discussions.unity.com/u/anon_75875665)
#### Post date: [August 5, 2010, 9:27pm UTC](https://discussions.unity.com/t/how-to-avoid-z-fighting/419792/7 "2010-08-05T21:27:16Z")

</div>

The FPS prefab contains a camera already (in the ‘head’ of the walker). Sorry, beyond that I don’t know how to access it.

---

<div class="post-metadata">

### Author: ![anon\_32068865](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@anon\_32068865](https://discussions.unity.com/u/anon_32068865)
#### Post date: [August 5, 2010, 9:44pm UTC](https://discussions.unity.com/t/how-to-avoid-z-fighting/419792/8 "2010-08-05T21:44:50Z")

</div>

Ok 🙂 thanks a lot everyone 😉 I found fixed it.

---

<div class="post-metadata">

### Author: ![Recluse](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/recluse/32/530610_2.png) [@Recluse](https://discussions.unity.com/u/Recluse)
#### Post date: [September 2, 2010, 7:38am UTC](https://discussions.unity.com/t/how-to-avoid-z-fighting/419792/9 "2010-09-02T07:38:36Z")

</div>

thanks for the info @sybixus2.

I am tweaking my near/far clip planes and this is useful to know.

I’m trying to find the ideal setting that doesn’t allow the player to see through walls they are touching while also providing a clear non-Zfighting view into the distance.
