Is this Raycasting circular spread code ok?

Here’s my favorite way to format a spread function:

local function RandomSpreadAt100Studs(cf, spread_diameter)
   local target_cf = cf * CFrame.new(0, 0, -100) -- Get a CFrame 100 studs ahead
      * CFrame.Angles(0, 0, math.pi * 2 * math.random()) -- Turn CFrame randomly on  the Z axis
      * CFrame.new(0, math.random() * spread_diameter / 2, 0) -- Pick a random spread distance from the origin ray
   return CFrame.new(cf.Position, target_cf.Position)
end
8 Likes