I am wondering how I could add random spread to a raycasting gun?
-- Define Some Things
local StudTravel = 250
local StartPosition = ShootPoint.Position
local Direction = (Position - StartPosition).Unit
local EndPoint = workspace:Raycast(ShootPoint.Position, Direction*StudTravel)
-- Define Some Things
local Intersection = EndPoint and EndPoint.Position or (StartPosition + Direction*StudTravel)
local Distance = (StartPosition - Intersection).Magnitude
-- Make Bullet
local NewBullet = MakeBullet:Clone()
NewBullet.Size = Vector3.new(0.1, 0.1, Distance) -- Distance
NewBullet.CFrame = CFrame.new(StartPosition, Intersection)*CFrame.new(0, 0, -Distance/2)
NewBullet.Parent = game.Workspace
--Add a random vector to direction
local Offset = Vector3.new(
math.random(-100,100),
math.random(-100,100),
math.random(-100,100)
)/100 * 0.25
Direction += Offset
Just know that there’s nothing more annoying to a player than a gun that doesn’t shoot straight.
Take a look at the game Fist Full of Frags for how it handles accuracy.
Its arcadey, but they’re a skill to aiming correctly.
I’m using it for a shotgun but I can’t seem to actually get the spread? I can’t seem to find the problem.
On a side note may be related. If I try running back and shooting the ray stops, can this all be something related to ignorelist? I don’t think I have one.
It’s not shown on the screen, but i’m using a for loop and running this function for each bullet. Is that the same thing? It was working every now and then (every 10 attempts), weird.