- Home /
bullet decals have wrong rotation C#
sorry for asking another question so soon, this should hopefully be quick. i made a script which makes a bullet leave a decal on the wall where it hits at a 20% chance. this works fine until you try in on walls facing different ways because the decal doesn't rotate to face away from the wall. any quick fix? im currently using the script:
if(collision.gameObject.tag == "Wall" && Random.value > 0.6) {
Instantiate(bulletHole, transform.position, Quaternion.identity);
}
thanks in advance :)
Answer by vexe · Aug 13, 2013 at 12:07 PM
You are always instantiating your bulletHole with a rotation of Quaternion.identity
, you need to have it be facing the wall it collides with, you could do that by getting the normal vector of the wall. Assuming this script is attached to the bullet: looking at it from the surface try
Instantiate(bulletHole, transform.position, Quaternion.Euler(collision.gameObject.transform.forward));
See if that helps.
unfortunately that seems to have no effect, no errors though. thanks anyways
Sorry, try collision.gameObject.transform.rotation
ins$$anonymous$$d of that Quaternion... - Which means, the rotation of the wall.
still no luck, but i think i know why. this is a very basic fps that i made, the walls are just extruded vertices, the entire map was originally from a single plane in blender, sorry for wasting your time
No it's O$$anonymous$$... ^^ this should be very easy to do, let me see...
Idk, it sounds right to instantiate it at the walls rotation, could you post all the relative code? what is the bulletHole prefab? a plane with a texture?
Answer by Linus · Aug 13, 2013 at 01:55 PM
See http://answers.unity3d.com/questions/8494/adding-decals-to-a-object.html
Assuming you are "shooting" using a raycast
var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
Instantiate(bulletHole, hit.point, hitRotation);
A ray is like a line, that you cast from one point to another. It can tell you which/what objects it hits along its way. Best way to handle shooting, I think is raycasting. So when you shoot, you cast a ray, and then check to see what they ray has hit. Did you try collision.gameObject.transform.rotation like I told you? - if you did and it didn't work, then I suggest you learn about Raycasting and how it works, and watch a few tutorials about raycast shooting on youtube. Good luck.
oh, that sounds handy. i did it a totally different way, Instantiate a bullet prefab and AddForce
Your answer
![](https://koobas.hobune.stream/wayback/20220613112116im_/https://answers.unity.com/themes/thub/images/avi.jpg)