Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ConorL · Sep 12, 2019 at 09:48 PM · randombullet

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by SuperScience · Sep 12, 2019 at 11:08 PM

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!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ConorL · Sep 12, 2019 at 11:38 PM 0
Share

That helps a ton! Thank you very much. Ya I've gotten to know the particle system using it as a back drop. What a diverse tool.

With this in $$anonymous$$d would I also be able to call different particle systems at different points to make different "stages" of the battle?

All the best.

avatar image SuperScience ConorL · Sep 23, 2019 at 04:05 PM 0
Share

Hi Conor,

Glad this worked out for you!

Could you do me a favor please and mark this as a Best Answer so I can get credit for helping you?

Thanks, and I hope your game turns out awesome.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

115 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Destroy bullet on random collision 2 Answers

Firing a curtain of bullets 1 Answer

shoot bullet at any direction(random) 0 Answers

Destroy Bullet on Random Collision 0 Answers

Create number of enemies when one is deid 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges