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:
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 .
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.
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,
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