So I am working on a projectile based fps project. I want there to be a specific decal for the wall when hit. My problem is, all the tutorials on youtube use raycasting to direction the bullet hits to be flat on the wall. How can I do that with a rigidbody bullet that spawns the bullet where the bullet makes contact with the wall. It works but the rotation is obviously off, it’s flat like a disc.
If the collider of the bullet hits the wall you get an impact point by the “OnCollisionEnter” method from the bullet collider. The “OnCollisionEnter” method provides “ContactPoint” from collision.contacts. Each ContactPoint has a normal vector. You can use this normal vector to rotate the decal in relation to the normals of the wall.
You can use this code to do the alignment of the decal spawn if you have find the contact point:
Vector3 startPos = hit.point;
Quaternion startRot = Quaternion.LookRotation(hit.normal);
Instantiate( decalPrefab, startPos, startRot );
1 Like
If you’re using OnCollisionEnter(Collision col)
the Collision parameter contains a list of ContactPoints contacts
, each of which contains a normal
Vector.
1 Like