Currently I’m working on a shotgun. However i’m countering a problem:
The shotgun spread is created by 3 random values, which can be explained by the following code:
local R1= math.random(-ShotgunConfigs.Radius.Value, ShotgunConfigs.Radius.value)
local R2= math.random(-ShotgunConfigs.Radius.Value, ShotgunConfigs.Radius.value)
local R3= math.random(-ShotgunConfigs.Radius.Value, ShotgunConfigs.Radius.value)
local ray = Ray.new(ShootPart.CFrame.p, (mouse.Hit.p - ShootPart.CFrame.p).unit * ShotgunConfigs.Range.Value + Vector3.new(R1,R2,R3))
Radius will be a value that defined by integer, in this case, the radius is 5.
However, seems that there’s a relationship between ShotgunConfigs.Range.Value
and the spread, the shorter the range is, the more spread it is, the longer the range is, the less spread it is, for instance, take a look on this picture which I did in MS paint
Orange line represents the spread when the range is 70 studs, Red line represents the range when it is 700 studs, as you can see the spread is different, and this is what I anticipate:
These 2 cases in game represented by bullet holes, in these 2 screenshots, I changed nothing except the range value:
How do I fix this? I know I have to do something with the range when creating a ray but exactly how?
Please do let me know if you are confused or have any questions.
Thanks