How to make Ray have Inaccuracy (For Gun)

You can write your topic however you want, but you need to answer these questions:
I’m Trying to make a gun with inaccuracy

if anybody could help me figure out a way I would be extremally grateful

I’ve tried this but It doesn’t seem to work properly

local maxRange = ((hit.Position - shootPoint).Unit + spread) * range
local BRay = Ray.new(TracerStart, maxRange)
3 Likes

Hey there!

One way to add spread could be by using a lookAt CFrame and then rotating it by a random value between [0, math.pi*2].
Then use the spread value to offset the angle.
In this example spread should be a value between 0 and 180

local direction = (CFrame.lookAt(shootPoint, hit.Position) 
	* CFrame.Angles(0, 0, math.pi * 2 * math.random()) 
	* CFrame.Angles(math.rad(spread/2) * math.random(), 0, 0)
).LookVector * range

local BRay = Ray.new(TracerStart, direction)
1 Like

thank you so much it works perfectly now!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.