How do you move the end of a ray left/right up/down ? I would be using this to create shotgun spread. I will be firing 12 rays how would I create a shotgun type spread with the 12 rays.
To move the end of the ray around, you need to multiply it's position by an offset. In your case the end position is most likely mouse.Hit.p
, yes? So what we need to do is provide an offset for the mouse.Hit. Things to do;
1) Make a variable for the minimum offset, and the maximum.
2) Use a numerical for
loop to create the ray 12 times.
3) Use a local variable to define the end of the ray's position within the loop, this should be mouse.Hit
multiplied by a CFrame with arguments of math.random methods from the minumum offset to the maximum.
local minO = 0 --minimum offset local maxO = 20 --max offset local shots = 12 --number of shots for i = 1,shots do --Define the origin for the end position of the ray local orig = mouse.Hit --Define the offsets for each axis. local xO,yO,zO = math.random(minO,maxO),math.random(minO,maxO),math.random(minO,maxO) --Define the end position of the ray, using the offsets. local finish = (orig.CFrame * CFrame.new(xO,yO,zO)).p --.p will return a vector local ray = Ray.new(handle.CFrame.p, finish) --Assuming 'handle' is defined.. wait(.1) end