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
  4. Dismiss Notice

Bullet Hole instaniated on wall have gaps between the hole and wall

Discussion in 'Scripting' started by SoloDevCsharp, May 4, 2021.

  1. SoloDevCsharp

    SoloDevCsharp

    Joined:
    Mar 5, 2021
    Posts:
    7
    Hi everyone! I am new to unity and working on a FPS project. I watched tutorials in Youtube and learned how to instantiate bullet holes using this script:
    if(hit.transform.tag == "DecalMove")
    {
    var decalHole = Instantiate(hitParticles, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)) as GameObject;
    decalHole.transform.position = hit.point;
    decalHole.transform.parent = hit.transform;
    }

    However, the bullet holes are not generated at the exact hit point on the wall. Just a little upwards on the surface, just like the following screenshots. Is there a way to adjust the object/decal position spawn on wall?
    Any hints would be appreciated.Thank you!! 1.png 2.png
     
  2. Widanon

    Widanon

    Joined:
    Jan 31, 2021
    Posts:
    36
    First check that the origin point of your bullet hole is in the centre - if it's at the bottom then your holes will appear above the spot you are shooting.

    Also, to adjust the position, if you need to, you instead of just assigning hit.point directly to your bullet hold, you can create your own Vector3, but adjust the values you pass in. I don't what hit.point is in your code, but assuming it's a transform, something like this..

    Code (CSharp):
    1. //replace 10f with whatever y offset you need..
    2. decalHole.transform.position = new Vector3(hit.point.x, hit, point.y - 10f, hit.point.z);
     
    SoloDevCsharp likes this.
  3. SoloDevCsharp

    SoloDevCsharp

    Joined:
    Mar 5, 2021
    Posts:
    7
    Thank you for speedy reply! I will try it imediately.