A fairly common issue, every time you fire a bullet it increase the potential spread angle.
The bullet direction is given as this: direction_cframe * CFrame.Angles(0, 0, math.pi * 2 * math.random()) * CFrame.Angles(getSpread() * math.random(),0,0)
What is best getSpread() function to use here?
Mine is rather complex, just wondering if someone has some simple yet realistic version to share.
Yes, I know this is not the most accurate one, but, I just modify the position obtained from the mouse click, and use courotines to fire multiple functions at once.
Looks realistic, works well and it is simple.
(If you are making a shotgun etc.)
But it is not really an equation.
It sounds like you could be conflating several different things here, including:
Accuracy of successive shots due to recoil
Shot distribution (“spread”) based on weapon characteristics (barrel length, tolerances, rifled vs non-rifled, muzzle velocity)
How shot distribution changes with barrel temperature (influenced by number of shots recently fired, and physical characteristics of barrel and how it was made)
How shot accuracy changes with skill, stance, and weapon position (ADS vs hipfire, firing while running vs standing still, clustering variance from unskilled vs skilled shooter, fatigue or injury level of shooter, etc)
Can you clarify what piece(s) you are reworking, and what your current solution looks like?
Im going for a very basic accuracy function. Simply the spread is a function of successive shots causing recoil.
The only weapon characteristic I have to fiddle with is ‘Accuracy’. Its a value around 0-200+ that defines the weapons accuracy.
I’d be willing to implement a second variable ‘Stability’ that could be increased with a frontgrip for example.
But thats about it. No other constants should be used to define a gun.
ADS simply divides spread by 2 as is done outside spread function.
Of course there is no “best” without knowing what you want, in reality bullet spread would remain pretty static and recoil would heavily depend on a lot of different factors. If you’re looking for the recoil to speed up or slow down a simple exponential function might do. But a general recoil mechanic in games is to move upwards and randomly left and right for each shot and stopping brings it back to the origin.
Seems reasonable for shot accuracy of a rifle or overall direction of each shotgun blast, based on sighting or not (not so much recoil, that’s handled differently like gullet mentioned). Where some games get it wrong though is they make ADS with a shotgun tighten the pellet spread significantly, so that hip firing is like having a sawed-off, and ADS a full length barrel. That’s lame IMHO.