ask a line what it hits
A raycast sends an invisible line from a point in a direction and returns the first object it touches. The result holds the hit point, the distance and the surface normal, shown here as the pink dot and the yellow arrow. Games use it for hitscan guns, line of sight, mouse picking and ground checks.
Use a raycast for hit detection: cast from the muzzle along the aim direction with a max distance of 100 units and a layer mask that skips the shooter, take the closest hit, and use its point and surface normal to place the impact effect.