I have been working on scripting my first gun recently. And I have got most of it working except bullet spread.

The problem I am having is bullet spread increases the closer your mouse it to the barrel of your gun.

Heres a gif to show you an example.

https://gyazo.com/3435f34daf2a3a427ad27723abdf67b5

Heres my code for the ray script.

	local BulletRay = Ray.new(BarrelPosition, (Vector3.new(MousePosition.X + Random.new():NextNumber(-Spread, Spread), 
		BarrelPosition.Y, MousePosition.Z + Random.new():NextNumber(-Spread, Spread)) - BarrelPosition).Unit

I only want spread on the X and Z axis because my game is top down.

Thank you for your time :) Have a gooood dayyyyy

5 comments

0

im kind of a noob to ray casting but maybe for the reference point(or whatever is linked to MousePosition) change it to HumanoidRootPart.CFrame * CFrame.new(0,4,0)?)

0

What do you mean>

0

instead of the mouse's position you use the humanoid's position plus 4 studs

0

I dont think that would work

0

why not?