So, I've written a bullet spread script, but there's a problem with it. No matter the range, the bullet will offset the same amount, making it possible to miss at point blank which obviously is an issue.
Here's my script, any ideas how to fix it?
local xOff = math.random(-spread * 100, spread * 100) xOff = xOff/100 local yOff = math.random(-spread * 100, spread * 100) yOff = yOff/100 local zOff = math.random(-spread * 100, spread * 100) zOff = zOff/100 local NewPos = mouse + Vector3.new(xOff, yOff, zOff) local ray = Ray.new(tool.firePart.CFrame.p, (NewPos - tool.firePart.CFrame.p).unit*300) local part, position = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList, false, true)
No wonder. Your script adds the spread to an already existing position.
You could try using trigonometry. But an easier way would be to multiply the base offset by the magnitude and then divide it by a constant.