Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to add spread using raycasting?

So I posted this earlier and I thought I had it. However, I found that the closer the target is, the more spread out the bullets will be. Is there an easy way to make the spread consistent no matter where the mouse is aimed on the screen?

local x = math.random(-3, 3)/math.random(10)
local y = math.random(-3, 3)/math.random(10)
local z = math.random(-3, 3)/math.random(10)
local spread = Vector3.new(x, y, z)
local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p + spread - tool.Handle.CFrame.p).unit * 300)

1 answer

✓ Accepted answer
local value = 10
local Spread = CFrame.Angles(math.rad(math.random(-value, value)/10), math.rad(math.random(-value, value)/10), math.rad(math.random(-value, value)/10))

local Ray = Ray.new(tool.Handle.CFrame.p, (CFrame.new(tool.Handle.CFrame.p, mouse.Hit.p) * Spread).lookVector.unit * 300)
local Hit, Pos, Normal = workspace:FindPartOnRayWithIgnoreList(Ray, Ray_Ignore)

1 comment

0

thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.