I suspect there are already built in functions to help with this, but if there aren’t I will need help with the math for this. I want to have my firearm have bloom when it’s shot, and I need help with transforming an initial vector (red) into that vector with a random twist and angle relative to its origin
It could also be thought of as getting a random point on a disc perpendicular to the initial angle, then make a vector from the initial position to that point.
Thanks in advance!
#Math for Firearm Bloom
1 messages · Page 1 of 1 (latest)
Why not just use a predefined particle system? Does it need to be so precise?
Particle system? How do you mean?
Can I use the emission shape of a particle system for other purposes in code?
Basically you try to visualize a muzzle flash, right? This is usually implemented by enabling particles and/or a mesh in that shape, potentially with an emissive material, and a light source.
Something like this:
https://youtu.be/_NjErIEp9tU?si=lw6ubmvshPtWkQyf
He means the bullet spread not the visual bloom effect
I never heard it called bloom either. In any case I would use something like random.insideunitcircle * maxSpread to get the gun rotation unless you need something more deterministic. You also probably want the first bullet to always fire straight.
They could:
- calculate the radius of the circle based on the angle and the distance to the hit point(opposite side from tan).
- Then get a random unit vector on a circle.
- project the vector on the circle plane.
- multiply the projected vector by the radius.
- add the multiplied vector to the circle center position.
The usual approach is just calculate a random x and y offset angle and rotate the vector by the resulting rotation
I've gotten good results with Random.rotationUniform + Quaternion.Lerp
However, this doesn't make it easy to pick an exact amount of spread
You also might want something non-uniform
it should be much more likely for a bullet to go near the center than way out at the edge
in that case, a 2D gaussian distribution would be great
i'd have to find the article again, but it's pretty easy to sample that distribution
this gives you a classic "bell curve" shape
I typically just do cs Quaternion offset = Quaternion.Euler(Random,Range(-xSpread, xSpread), Random.Range(-ySpread, ySpread), 0); Vector3 projectileDirection = offset * muzzleDirection;
It also depends on how realistic you want it to be. If this is full auto, then the spread should be tracking upwards with the recoil