Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to add spread using raycasting?

Asked by 6 years ago

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

Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
6 years ago
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)
0
thank you sonicfan0405 18 — 6y
Ad

Answer this question