# How do I use raycast to put a bullet hole on a curved surface?

EDIT: As of yet I have not been able to find a way to make the bullet hole wrap around the corner of a gameobject.

I am working on a fps game that uses raycast for shooting and so far it works, but the problem is with the bullet holes. So the script will generate bullet holes (not going to explain everything it does) like it is supposed to.

The problem is that if I shoot the corner the bullet hole will just generate on whatever side the impact was closest to. How do I get the bullet hole to spawn on curves and corners? Here is the script:

public class HitFXManager : MonoBehaviour
{

[Range(1, 200)]
public int decalsPoolSizeForEachType;

public GameObject concreteDecal;
public GameObject woodDecal;
public GameObject dirtDecal;
public GameObject metalDecal;

[HideInInspector]
public GameObject[] concreteDecal_pool;
[HideInInspector]
public GameObject[] woodDecal_pool;
[HideInInspector]
public GameObject[] dirtDecal_pool;
[HideInInspector]
public GameObject[] metalDecal_pool;

void Start()
{
DecalsPool();
}

public void DecalsPool()
{
concreteDecal_pool = new GameObject[decalsPoolSizeForEachType];
var decalsParentObject_concrete = new GameObject("decalsPool_concrete");

for (int i = 0; i < decalsPoolSizeForEachType; i++)
{
concreteDecal_pool[i] = Instantiate(concreteDecal);
concreteDecal_pool[i].SetActive(false);
concreteDecal_pool[i].transform.parent = decalsParentObject_concrete.transform;
}

woodDecal_pool = new GameObject[decalsPoolSizeForEachType];
var decalsParentObject_wood = new GameObject("decalsPool_wood");

for (int i = 0; i < decalsPoolSizeForEachType; i++)
{
woodDecal_pool[i] = Instantiate(woodDecal);
woodDecal_pool[i].SetActive(false);
woodDecal_pool[i].transform.parent = decalsParentObject_wood.transform;
}

dirtDecal_pool = new GameObject[decalsPoolSizeForEachType];
var decalsParentObject_dirt = new GameObject("decalsPool_dirt");

for (int i = 0; i < decalsPoolSizeForEachType; i++)
{
dirtDecal_pool[i] = Instantiate(dirtDecal);
dirtDecal_pool[i].SetActive(false);
dirtDecal_pool[i].transform.parent = decalsParentObject_dirt.transform;
}

metalDecal_pool = new GameObject[decalsPoolSizeForEachType];
var decalsParentObject_metal = new GameObject("decalsPool_metal");

for (int i = 0; i < decalsPoolSizeForEachType; i++)
{
metalDecal_pool[i] = Instantiate(metalDecal);
metalDecal_pool[i].SetActive(false);
metalDecal_pool[i].transform.parent = decalsParentObject_metal.transform;
}

}
}

• Is this really a raycasting problem, or just a decal-ing problem? ie. Do you need help detecting the hit point on the curved surface? Or just with stamping a known hit point with a hole decal that fits the curve? Jul 29 '19 at 22:32
• @DMGregory You are right I will take the raycasting tag off. I updated my question and put my script in. Jul 29 '19 at 23:09
• Presumably you considered using deferred decals for this? Jul 29 '19 at 23:21
• @DMGregory Are you talking about the \$5 asset in the asset store? Jul 29 '19 at 23:35
• There are many assets that implement this technique, or you could roll your own if you prefer. Jul 29 '19 at 23:35