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 Galdik · Sep 11, 2016 at 04:58 PM · particle systememission

how to make particles start with smaller emission rate and than keep it constant while holding a key

Hello, I'm making 2D pirate ship game and having some trouble with particle system. This is how it looks like when moving right now. alt text

I would like the particle system to emit less particles when ship is just starting to move and when it slowly stops. So emission rate is not constant all te time the ship is moving.

I'm using this script:

 private ParticleSystem trail;

 
 void Start ()
 {
     trail = GetComponent<ParticleSystem>();
 }
 
 
 void Update ()
 {
     if(Input.GetKey(KeyCode.UpArrow))
     {
         trail.Play();
     }
     else
     {
         trail.Stop();
     }
 }

}

As you can see particle system is only played when i hold UpArrow key. I'm also curious if it's possible to emit particles while the ship is still moving and stopping slowly after i already released the key. Is there any method or smthg that says that this particle system will play simply when the object it's attached to is moving?

Thank you very much for answers!

lodka.jpg (10.3 kB)
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
0

Answer by iabulko · Sep 12, 2016 at 04:07 PM

You can easily check if object is moving by checking the difference between it's actual position and position from last frame. You can also make emission rate dependent from it's speed using that difference, for example:

     private ParticleSystem trail;
     public GameObject ship;
     private Vector3 lastPosition;
 
     void Start ()
     {
         trail = GetComponent<ParticleSystem>();
         lastPosition = ship.transform.position;
     }
 
 
     void Update ()
     {
         if(Input.GetKey(KeyCode.UpArrow))
         {
             trail.Play();
         }
         else
         {
             trail.Stop();
         }
 
         float speed = Vector3.Distance (ship.transform.position, lastPosition);
         var em = trail.emission;
         var rate = new ParticleSystem.MinMaxCurve();
         rate.constantMax = speed;
         em.rate = rate;
 
         lastPosition = ship.transform.position;
     }
Comment
Add comment · Show 1 · 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 Galdik · Sep 14, 2016 at 02:47 PM 0
Share

thank you very much @iabulko for your help but the script doesnt seem to work for me. I'm probably doing smthg wrong but after using your example nothing actually changed, the ship is still emitting particles only when I hold uparrow key. I have emission rate set to 66 in the inspector should I change it to curve ins$$anonymous$$d or I totally don't get the point? :D

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Particle emission : Give each particle a specific direction 1 Answer

Particle System not working properly on Android 0 Answers

Emit 1 particle per second 1 Answer

Particle system does not re-emit until Start Lifetime elapsed 4 Answers

Particle System Still Emitting Particles Even If Emission Is 0 0 Answers


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