Recently I have been working on a Shotgun. So basically it creates a ray inside a for loop because a Shotgun shoots multiple bullets.
I created the Shotgun Pattern by a random number between
radius can control the spread of it. Suppose it’s value is 8 here.
for i = 1,15 do local ray = Ray.new(Shotgun.ShootPart.CFrame.p , (mouse.Hit.p - char.Shotgun.ShootPart.CFrame.p).unit*50 + Vector3.new(random1,random2, Shotgun.Radius.Value)) ...
And the Raycast will ignore the bullet itself:
local hit,pos = workspace:FindPartOnRay(ray, BulletTrail)
And it will find the distance:
local distance = (char.Shotgun.ShootPart.CFrame.Position - pos).magnitude BulletTrail.Size = Vector3.new(0.05,0.05,distance) BulletTrail.CFrame = CFrame.new(char.Shotgun.ShootPart.CFrame.p, pos) * CFrame.new(0,0,-distance/2)
So this should be an expected result:
You can see the bullets are spreaded clearly, going on it’s own way.
However, sometimes the distance returns to 0.01, shown below:
In this image you can clearly see there’s only one bullet trail, other than that they won’t “expand”
I’m sure there’s no invisible walls blocking the ray, I’m not sure is my
FindFirstOnRay went wrong, or any algorithm is incorrect here, please let me know if you have any ideas or if you are confused, Thanks!!