How to spread like a shotgun with direction? (new raycast system)

Hey, I’ve got a question, I’ve got this so far;

for i = 1,6 do
			caster:Fire(RaycastStart,Direction,Configurations.Distance or 200 ,castBehavior)
		end;

It uses new raycast system, how can I make “Direction” spread randomly?
Direction is a lookvector so what i’m trying to do its for it to spread

Right now;
image
What I want;
image

1 Like

When adding into direction like this;
Direction + Vector3.new(math.random(-1,1),0,0)
It doesn’t works right.

I want sort of a circular spread

You could rotate the direction

local SpreadMax = 10 -- Spread in degrees
for i = 1, 6 do
	local ray = CFrame.new(RaycastStart, RaycastStart + Direction) * CFrame.fromEulerAnglesXYZ(math.deg(math.random(0, SpreadMax)), 0, math.deg(math.random(0,360)))
	caster:Fire(ray.Position, ray.LookVector * (Distance or 200), castBehavior)
end

Idk if you can see it, but I guet this result;

My bad, I should’ve used math.rad not math.deg, try this instead

local SpreadMax = 10 -- Spread in degrees
for i = 1, 6 do
	local ray = CFrame.new(RaycastStart, RaycastStart + Direction) * CFrame.fromEulerAnglesXYZ(math.rad(math.random(0, SpreadMax)), 0, math.rad(math.random(0,360)))
	caster:Fire(ray.Position, ray.LookVector * (Distance or 200), castBehavior)
end
4 Likes