- Home /
Creating decal, terrain normals not working
I am creating bullet hole decals on objects when I shoot them. This works on everything except for terrain where the decals will sometimes hover over the terrain and never have the correct rotation (always pointing up). Here's the code:
Vector3 hitPosition = new Vector3 { x = collision.contacts[0].point.x, y = collision.contacts[0].point.y, z = collision.contacts[0].point.z };
Quaternion rotation = Quaternion.FromToRotation(Vector3.up, collision.contacts[0].normal);
//Create the decal (ie: bullet hole)
GameObject decal = (GameObject)Instantiate(DecalPrefab, hitPosition, rotation);
Answer by Statement · Mar 20, 2011 at 10:57 PM
I think you should use Quaternion.LookRotation rather, and note that the order is reversed if you want to supply the up vector. The up vector come as second argument. Does this do the trick?
ContactPoint contact = collision.contacts[0];
Quaternion rotation = Quaternion.LookRotation(contact.normal);
GameObject decal = (GameObject)Instantiate(DecalPrefab, contact.point, rotation);
Your answer
Follow this Question
Related Questions
put blanket on the ground 2 Answers
Procedural heightmap shader - Normals and tangents 0 Answers
Normal map on Terrain ? 1 Answer
HDRP Decal projection from mesh shape, e.g. for creating a winding road 1 Answer
Decaling! how to! Help! 2 Answers