How to add bullet spread with Fastcast?

Is there any way to add bullet spread with Fastcast?

local origin = firearm:WaitForChild("BulletExit"):WaitForChild("Attachment").WorldPosition
			local direction = (mousePos - origin).Unit
			
			local caster = fastcast.new()
			
			local behavior = caster.newBehavior()
			behavior.MaxDistance = 1000
			behavior.RaycastParams = params	
			
			caster.LengthChanged:Connect(function(cast, lastpoint, dir, length)
				local blength = bullet.Size.Z / 2
				local offset = CFrame.new(0, 0, -(length - blength))
				bullet.CFrame = CFrame.lookAt(lastpoint, lastpoint + dir):ToWorldSpace(offset)
			end)
				
			caster.RayHit:Connect(function(ray, result)
				local hit = result.Instance
				
				-- Destroy the bullet after it hits something
				bullet:Destroy()

				
				if hit:FindFirstAncestor("Zombies") then
					local character = hit:FindFirstAncestorOfClass("Model")
					local humanoid = character:FindFirstChildOfClass("Humanoid")
					print(hit)
					if humanoid and hit.Name == "Head" then
						humanoid:TakeDamage(20)
					end
					
					if humanoid and hit.Name ~= "Head" then
						humanoid:TakeDamage(10)
					end
				else
					-- If the bullet hits something other than a zombie, make a hole where it lands
					local randomBulletHoleDecalClone = bulletHolesTable[math.random(1, #bulletHolesTable)]:Clone()

					local randomBulletHoleDecalPart = Instance.new("Part")
					randomBulletHoleDecalPart.Name = player.Name .. "_BulletHole"
					randomBulletHoleDecalPart.Transparency = 1
					randomBulletHoleDecalPart.CanCollide = false
					randomBulletHoleDecalPart.Anchored = true
					randomBulletHoleDecalPart.Size = Vector3.new(0.5, 0.5, 0.1)
					randomBulletHoleDecalClone.Parent = randomBulletHoleDecalPart
					randomBulletHoleDecalPart.Parent = workspace.Projectiles["Bullet Holes"]
					randomBulletHoleDecalPart.CFrame = CFrame.new(result.Position, result.Position + result.Normal) * CFrame.new(0, 0, 0)
					
					-- Destroys Decal after 10 seconds
					game.Debris:AddItem(randomBulletHoleDecalPart, 10)
				end
				
				
			end)
			
			caster:Fire(origin, direction, bulletVelocity, behavior)

I’ve tried using math.random, but maybe I’m doing it wrong. It shoots straight and where I want it to, but I kind of want to add a little spread.

Funny there was a thread just about this here How to make cone-shaped bullet spread? - #4 by McThor2

Basically your direction vector just needs multiplying by a CFrame and it will cause a slight spread.

2 Likes

You could change the orientation of the bullets a little bit.

1 Like