Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Bullet holes disappear when moving about FPS

Discussion in 'Scripting' started by GForce007, May 27, 2016.

  1. GForce007

    GForce007

    Joined:
    May 22, 2015
    Posts:
    27
    Hi Guys!!

    I have a FPS game that I'm building and my guns shoot with racasts, but when a bullet hole is instantiated it pops in and out( if that makes sense ), when I'm moving around in the 3D world. It's almost like the bullet hole texture is just underneath the surface it's instantiated on.

    I know I should try to instantiate the bullet hole just a bit more above the surface, but I have no idea how.

    Can anyone help?

    Thanx!!!

    Code (csharp):
    1.  
    2.  
    3. if (Physics.Raycast(ray, out hit, 50f) && hit.collider.tag != "Bullet" && hit.collider.tag != "Default")
    4.                 {
    5.                     GameObject bulletHoleClone = Instantiate(bulletHole[0], hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)) as     GameObject;
    6.                     bulletHoleClone.transform.parent = hit.transform;
    7.                 }
    8.  
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    sounds like "z fighting", the textures are in the exact same position and the renders flicks between the two.


    Try

    Code (csharp):
    1.  
    2. hit.point + (hit.normal * 0.01f)
    3.  
    for the position
     
    ericbegue likes this.
  3. GForce007

    GForce007

    Joined:
    May 22, 2015
    Posts:
    27
    Absolutely perfect!! Thanx!! and thanx for the quick reply as well!!!