1 | local ray = Ray.new(tool.Shooter.CFrame.p, (mouse.Hit.p - tool.Shooter.CFrame.p).unit* 300 ) |
I'm stumped on what to change to make this bullet spread.
The Ray.new function has a syntax of;
Ray.new( Vector3 origin, Vector3 end)
So what you need to do is offset the look argument by a wanted minimum and maximum CFrame, using math.random
.
01 | math.randomseed(tick()) --to make it completely random |
02 |
03 | --Define offsets for each axis |
04 | local xMin,xMax = 0 , 10 |
05 | local yMin,yMax = 0 , 10 |
06 | local zMin,zMax = 0 , 10 |
07 |
08 | --Define origin |
09 | local origin = tool.Shooter.CFrame |
10 |
11 | --Define look as mouse.Hit multiplied by randomized offsets |
12 | local look = mouse.Hit * CFrame.new( |
13 | math.random(xMin,xMax), |
14 | math.random(yMin,yMax), |
15 | math.random(zMin,zMax) |
16 | ) |
17 |
18 | --Create the ray |
19 | local ray = Ray.new(origin.p, (look.p - origin.p).unit* 300 ) |