I have a blueprint that allows me to fire bullets from a gun, and a function which inputs a bullet rotation, and randomizes it so that it may have bullet spread. All was working well, until I payed attention. After firing around 1000 bullets, I noticed a very strange pattern (see the picture below):
I could’ve sworn I did not have this same pattern yesterday, or even earlier today, I did not change anything in the rot randomization function. Here is a picture of the function:
Why in the world is there a pattern in this function? Is the math in the function somehow off in a way that is would create a pattern? I very much appreciate any answers, thanks ahead of time!
Edit: The rotation that I am inputting into my function is my player’s Control Rotation.
It doesn’t need to be just light btw, it can be any form of wave mechanic, which seems to be going on here. What’s hugely interesting about this was that you were able to simulate the same effect without needing to build a multi-million dollar machine to fire “rays” through. Perhaps you should post on either a physics forum or MIT forum about your findings?
At least submit it to peer review, maybe someone can give an answer on this?
But if that’s the case, which part of my function’s math could be causing this? I’m really not sure what I would write on a Physics forum that would help me solve this :\
I would recomend you to do it in a different way. Create one float for the spread amount, and then other float for the “angle”, you then just offset it in that direction by the magnitude you calculated. Should give you more round spread, and if you modify the magnitude, you can make it so most shots go in the center more than in the sides.
Well, it’s not to “solve” it so much as to demonstrate the capability of using the engine as a real-time simulation of the effect on the “real world”. So far, there hasn’t been any use-case for this phenomena other than chaos theory textbook stuff.
Hah
I saw this pattern the first time when I played around with my Commodore C128.
Later on the PC, I could achieve the same with GW Basic.
It seems to be an effect of drawing a large quantity of random numbers that are based on the same seed.
If I create a program that randomly puts dots in a 500x500 field and visualize that, I get the same patterns.
When I asked my high school teacher about it, he said that it has to do with how computers represent and process floating point numbers.
Does that mean that the seed remains a constant throughout the duration of the game? Using a random seed in my random does not change this. How would I avoid this problem?
That largely depends on how the random function is implemented on the low level. I dont know how C++ does this.
Maybe its some sort of a shift register…
What you could do is: Change the probability with each subsequent shot. This could be done in the following way:
Imagine a 2 dimensional array of potential gun trajectories, like a grid in front of the gun.
Now assign each cell in that array a linear index. and create a list of them.
Say, we have a 3x3 array, which means 9 possible impact points for the bullet, with the center cell representing the “true aim”.
The player fires now a shot.
You draw a number from the index list and thats the cell where the bullet will go, with a probability of 1/9.
Remove the entry from the index list.
The player fires now another shot.
You draw a number from the index list and thats the cell where the bullet will go, with a probability of now 1/8.
Remove the entry from the index list.
etc. Until the last shot is not a matter of probability anymore…
This way you have an even spread guaranteed. (no 2 bullets can hit the same spot and all spots will be hit).
If you make the array size of possible hits the same size of your intended ammo clip capacity and reset the grid after each reload, you only need a very small grid/list to achieve the desired effect.
PS: The “hit coordinates”, stored in the array do not necessarily have to be equidistant.
So, even as indeed the entire array is completely covered, the bullets may still not form a grid like pattern…
In this case the random number not sure if is a problem because is a weapon and probably you need the 80% of the bullets go to the middle more or less, but keep in mind the default and the only one UE4 random number generator don’t generate uniform distribution values.
I had yet another idea for making your calculations:
You create random vector in a cone.
Then you do “Get look rotation at”. And make it from [0,0,0] to your vector value.
This should be same as your graph.