# Help with bullet spread pattern

I’m in the process of making a bullet hell style game. I’ve used a variation of the Laser Defender tutorials firing methods and right now I have the bullets spawning where I want them but each pattern is restricted to the enemies origin. Here’s the code

void Fire()
{
Vector3 startPosition = transform.position + new Vector3(5, -7f, 0);
GameObject missile = Instantiate(projectile, startPosition, Quaternion.identity) as GameObject;
missile.GetComponent().velocity = new Vector2(10, -projectileSpeed);

``````    Vector3 startPosition2 = transform.position + new Vector3(-5, -7f, 0);
GameObject missile2 = Instantiate(projectile, startPosition2, Quaternion.identity) as GameObject;
missile2.GetComponent<Rigidbody2D>().velocity = new Vector2(-10, -projectileSpeed);

Vector3 startPosition3 = transform.position + new Vector3(0, -7f, 0);
GameObject missile3 = Instantiate(projectile, startPosition3, Quaternion.identity) as GameObject;
missile3.GetComponent<Rigidbody2D>().velocity = new Vector2(0, -projectileSpeed);
``````

As you can see there’s 3 points where the bullets come from but they fall in a linear pattern so its pretty easy to just stay in between the bullets. Any way to add a random variable to have them a little more scattered?

Hi there Conor.

This is probably the last thing you want to hear, but if you’re trying to do bullets, especially for a bullet hell type game, its much easier if you use the Particle System rather than instancing individual projectiles.

Particles are like gameobjects that the game instantiates for you, depending on a bunch of parameters. You can tailor them pretty easily though. But they also have the advantage of being highly optimized on render (they all render in 1 pass for 2D particles, not 100% sure for 3D particles).

You can create a particle system, which is a thing that emits particles, by adding a ParticleSystem component. As soon as you do, you will see kinda pink squares or white globes coming out of a central point.

Anyway, using this particlesystem, you can specify that you want particles to be instanced as a cone, (in the shape) and you give an angle, and the number of projectiles (in emitter), and it just works.

There are A LOT of knobs and dials here, which would be difficult for me to explain in detail. You may have to explore a bit on your own. But I suspect you want to set the space to WORLD space (so the particles don’t move if you turn the “gun”). You probably want to turn off PlayOnAwake, and Looping, and then set your enemy controller to call ParticleSystem.Play(), which will kick off your particle sequence.

Then you can build one sequence for each pattern of bullets that emerge from this enemy (or hero)

Then you turn on collisions and tell it to send collision messages.

In your player script, it will call the OnParticleCollision method upon collision, which passes the originator of the particle, and you can use that to determine how much damage is done. (For example, a big bullet might come from a canon, and then you can do something like gameobject.getComponent().getDamageAmt() and tally your damage there.

Hope this helps!