The raycast was casted from an invisible part named ShootPart which is positioned in the front of the barrel, here’s some part of the code:
local ray = Ray.new(ShootPart.CFrame.p, dir * ShotgunConfigs.Range.Value)
...
local distance = (ShootPart.CFrame.Position - pos).magnitude
BulletPart.CFrame = CFrame.new(ShootPart.CFrame.p, pos)
The problem is pretty simple: The shootPart is situated at the end of the barrel. You should move it backwards so the start of the ray does not go through objects.
Can you show how big the ShootPart is on your weapon?
When you do ShootPart.CFrame.p, that refers to the center of the part. There’s a chance that the ShootPart’s center is offset from the end of the barrel.
Then that is why the gun is shooting forward that much. You start the ray there, so it can easily clip through walls. Try moving the part back towards the gun.
You should check the visual bullet trail code again. The trails depicted in the video would seem to have the correct focal point from the shootpart, and not intersecting like what being placed way ahead would suggest.
This doesn’t seem to be an issue with raycasts at all, but rather where the bullet is when the trail first renders. Trail.MinLength and Trail.MaxLength may also not have the ideal settings for how you want it to look.
not sure if this would work but yeah
( This what I did in my prototype gun system, and Yes I had shotguns and such I’ll post a screenshot of how it looked like, not the best but I was just testing serverside hit detection )
I use that for all my guns and this is the output I always get and is expected :
(If it wasn’t obvious from the video then uh my spread is handled differently and uses something else for spread and accuracy, so yes my answer assumes that it’s the spread system that’s not broken)
Also is it possible for you to show us how what “dir” is?