Creating Bullet Holes via Raycasting

Objective: Instantiate bullet hole decals with raycasting

Ed Hepplewhite
Aug 20, 2023

To get started we’ll need to setup a scene with a wall, an fps controller, a gun reticule, and some bullet hole decals.

Then, create a shoot script and attach it to the player controller.

We will need a reference to the bullet hole prefab. Next, we can setup our raycast.

This first checks to see if the mouse button has been pressed. If it has, it performs a raycast using the center of the camera viewport to generate a ray. Then, it instantiates the bullet prefab at the hit point. Last, it rotates the decal to be normal to the surface and adds a slight offset so there isn’t any z fighting of the decal and the surface.

--

--