#Math for Firearm Bloom

1 messages · Page 1 of 1 (latest)

glad gust
#

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!

oblique veldt
#

Why not just use a predefined particle system? Does it need to be so precise?

glad gust
#

Particle system? How do you mean?

#

Can I use the emission shape of a particle system for other purposes in code?

oblique veldt
#

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.

abstract canyon
oblique veldt
#

Oooh. I see. Didn't know that terminology.

#

Why not just say "bullet spread"?

abstract canyon
#

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.

oblique veldt
#

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.
bold skiff
gentle stump
#

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

gentle stump
bold skiff
#

I typically just do cs Quaternion offset = Quaternion.Euler(Random,Range(-xSpread, xSpread), Random.Range(-ySpread, ySpread), 0); Vector3 projectileDirection = offset * muzzleDirection;

abstract canyon
#

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