What solutions have you tried so far? I tried to find solutions on devforum
Hello, I want to make bullet spread system and bullet visualization with raycast, what is the best way for me to do this?
For now I use this :
local Pos = currentGun.Fire.Position
local hit = plr:GetMouse().Hit
local origin = Pos
local direction = (hit.Position-Pos)*1000
local params = RaycastParams.new()
params.FilterDescendantsInstances = {char, camera}
params.FilterType = Enum.RaycastFilterType.Exclude
local ray = workspace:Raycast(origin, direction, params)
local direction = (hit.Position-Pos)*1000
direction *= CFrame.Angles(math.radians(math.random(0,3)), math.radians(math.random(0,3)), math.radians(math.random(0,3)))
local Pos = currentGun.Fire.Position
local hit = plr:GetMouse().Hit
local origin = Pos
local direction = (hit.Position-Pos)*1000
direction *= CFrame.Angles(math.radians(math.random(0,3)), math.radians(math.random(0,3)), math.radians(math.random(0,3))) --here im getting error 'Attempt to call a nil value’
local params = RaycastParams.new()
params.FilterDescendantsInstances = {char, camera}
params.FilterType = Enum.RaycastFilterType.Exclude
local ray = workspace:Raycast(origin, direction, params)
Error - ‘invalid argument #1 (CFrame expected, got Vector3)’
Here is my edited code
local direction = (hit.Position-Pos)*1000
direction *= CFrame.Angles(math.rad(math.random(0,3)), math.rad(math.random(0,3)), math.rad(math.random(0,3)))
local spreadAmount = 5 -- Adjust this value to increase or decrease spread
local randomSpread = Vector3.new(math.random(-spreadAmount, spreadAmount), math.random(-spreadAmount, spreadAmount), math.random(-spreadAmount, spreadAmount))
local direction = ((hit.Position + randomSpread) - Pos) * 1000
I suggest trying out FastCast, it’s a far better alternative rather than default roblox raycasting, also offers ways to visualize bullets (Also mark my solution pls):