Bullet spread with BodyVelocity bullets?

I want to add a bullet spread thing for the gun of an NPC, well, the problem is that i don’t know how to do it, currently, the gun is not using Raycast, the script creates a part, using a BodyVelocity to push the bullet to the front of the NPC, something like this:

local bv = Instance.new("BodyVelocity")
bv.Parent = Bullet
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = r.CFrame.LookVector * 500

Well, as previously said, i want to add a bullet spread system, which i don’t know how it works, yes, i already searched through the forum, however, i didn’t found an useful thread. Thanks for reading. If you need more information, feel free to ask me :+1:.

I think you should do it like

local spread = math.random(0,100)/100

bv.Velocity = (r.CFrame.LookVector + Vector3.new(spread,spread,spread)) * 500

but I think racyasting is a better way of making guns instead of body velocity

1 Like

Than, although that may be true, he may be wanting something that actually travels over being instantaneous. Which even still he should look into Making a combat game with ranged weapons? FastCast may be the module for you!

For any reason it’s still not working:


As you can see, the bullets have the same rotation.

You can use physics for this! And touched events. But your bullet velocity should be more like 250 and the bullets will have to be 2 studs. 350studs/sec? I used .1 by 4.2 by .1 for my M1 Garand. You can hide them, or be like me and like the tracer effect!

I did this before I knew raycast, and I don’t regret it either.

https://i.gyazo.com/10d6205cac770a490ac74ca4d7d5f264.mp4

and here’s the bullets

image

I used these in 2017. I can make them a model if you like.

Nice! Thanks for the tips. However, what i’m asking is how do i add bullet spread in my NPC’s gun.

Oh, apologies! If you want spread you have to find some neat little equations if you want it done right, check this out:

you ought to pay close attention to the intended result at right,
image
just set this up, and, come time, to shoot the ray these points will be used as the lookVectors. I’m sure someone on here can further add to this solution.

First time I integrated this was with the laser gun article on the Learn Roblox wiki. It’s still up, simple, Intro to Raycasting I would just add this functionality to it to make sure you can manage it by itself before going on to make your more complex end product!

r.Position = ThePositionWhereTheBulletExits
--Add a line that makes the bullet face the mouse position
r.CFrame = r.CFrame * CFrame.Angles(0,math.random(-1,1),0)

--Add your BodyVelocityScript
BV.Velocity = r.CFrame.LookVector * 50

You can change the value of the math.random if you want