- Home /
Found a work around for this problem, by creating a random number 1-10, checking if it was under 5, and if so, dividing the offset of a bullet by 2.
How to create a standard deviation number generator?
I am making a fps, and want to have spread, but for a majority of the shots to be closer to the center. How would I do this? Also, if possible is there a way to do it so the final range is - bulletfloat, bulletfloat, where bullet is a public float, that can be changed?
Answer by Llama_w_2Ls · Jan 22, 2021 at 09:24 AM
You could try offsetting your bullets by Random.insideUnitCircle
. This returns a random Vector2 within a circle of radius 1. You could add this to your bullet.transform.position, to create a random bullet spread. You can half the value of Random.insideUnitCircle
if you find that the bullet spread is a bit too wide. @WryanD
Answer by $$anonymous$$ · Jan 22, 2021 at 12:38 PM
float r = mean + standardDeviation * sqrt(-2 * Mathf.Log(UnityEngine.Random.value)) * sin(2 * Mathf.PI * UnityEngine.Random.value);
Follow this Question
Related Questions
Getting an inversely proportionate value 1 Answer
Random.Range(..) not working 1 Answer
RNG output to a variable + instantiating a prefab based on said variable? 1 Answer
Randomly generated number 0 Answers
Writing maths expressions 1 Answer