- Home /
Issue displaying bullethole decal on collision object
Hey all, I'm having an issue with my raycast shooting script. It's very simple, and as of right now it's working, however when you see the decal on the object it looks very sketchy. You'll see what I mean in my photo:
If anyone can help me I'd appreciate it!
Here's my code:
if (Input.GetButtonDown("Fire1") && Physics.Raycast(barrelPoint.transform.position, fwd, out hit, 100))
{
Debug.DrawRay(barrelPoint.transform.position, fwd, Color.green, 100);
var hitRotation = Quaternion.FromToRotation(Vector3.back, hit.normal);
var go = Instantiate(bulletHole, hit.point, hitRotation);
Destroy(go, 5);
}
Answer by eitanwass · Oct 10, 2018 at 05:53 PM
Move the bullet hole object a bit away from the wall. It is intersecting with the wall so in certain points the meshes overlap. Try:
var go = Instantiate(bulletHole, hit.point + 0.01 * hit.normal, hitRotation);
I recieve this error "Operator * cannot be applied to operands of type 'double' and 'vector3'
I realized why you didnt respond...it was pretty damn easy. All I had to do was add the f after your 0.01 to make it a float and it worked.
So I created a var: var wallDistance = .02f * hit.normal;
Then simply called the var like this: if (Input.GetButtonDown("Fire1") && Physics.Raycast(barrelPoint.transform.position, fwd, out hit, 100)) { Debug.DrawRay(barrelPoint.transform.position, fwd, Color.green, 100); var hitRotation = Quaternion.FromToRotation(Vector3.back, hit.normal); var go = Instantiate(bulletHole, hit.point + wallDistance, hitRotation); Destroy(go, 5); }
Your answer
![](https://koobas.hobune.stream/wayback/20220612180120im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
issue with bullet hole decal 1 Answer
Raycast script help? 1 Answer
C# raycast shooting script broken 1 Answer
hit.normal rotation problem, help please really confused 1 Answer