Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Gaussian Distribution in circle on x and y axis

$
0
0
Hey, so I have a weapon script which is exactly like CS:GO, except for the weapon spread. As you know if you've played said shooter, you know that your bullets become less accurate the longer you hold the fire button. My script can do this, but it does so in a square using normal distribution. I want it to instead be in a circle and using gaussian distribution! I don't know quite how gaussian distribution works yet, but Ive found a short script that does it, but I can't figure out how to do it in a circle! Here is the necessary parts of my weapon script: //NOT MADE BY ME public static double NextGaussianDouble() { double U, u, v, S; do { u = 2.0 * Random.value - 1.0; v = 2.0 * Random.value - 1.0; S = u * u + v * v; } while (S >= 1.0); double fac = Mathf.Sqrt(-2.0f * Mathf.Log((float)S) / (float)S); //I just changed the doubles to floats. Is there any point in using doubles at all in this case? return u * fac; } That was the gaussian distribution, and here is the part that makes the direction: w.CurSpread += 1.0f/w.MaxAmmo; w.Spread = w.SpreadSpeed.Evaluate(w.CurSpread)*w.MaxSpread; float spread = w.Spread * (float)NextGaussianDouble(); Vector3 x = ((weapon[selected].right * w.PatternX.Evaluate(w.CurSpread) * w.Recoil.x) + (weapon[selected].right * spread)); Vector3 y = ((weapon[selected].up * w.PatternY.Evaluate(w.CurSpread) * w.Recoil.y) + (weapon[selected].up * spread)); Vector3 direction = (x + y + weapon[selected].forward*100); This version of the script nails the distribution, but it sprays it in a diagonal line! I want it to spray in a circle! Please help!

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>