Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 graham · Apr 15, 2012 at 10:39 AM · particlesparticlesystemshuriken

Adjusting speed of existing particles

I have a particle system and I want to control the velocity of emitted particles. I can modify the emission speed of new particles, but I want to also adjust the velocity of particles that already exist. I assumed I could do that by getting the particles, updating the velocities and setting the particles again, but when I then check the velocities the next frame, they're unchanged.

Here's the code:

 void LateUpdate()
 {
     if (mUpdateParticleSpeed)
     {
         mUpdateParticleSpeed = false;
         
         // Update particle velocities, assumes constant velocity
         int numParticles = particleSystem.particleCount;
         ParticleSystem.Particle[] particles = new ParticleSystem.Particle[numParticles];
         particleSystem.GetParticles(particles);

         for (int i = 0; i < particles.Length; i++)
         {
             var particle = particles[i];
             particle.velocity = particle.velocity.normalized * mParticleSpeed;
         }
         
         particleSystem.SetParticles(particles, numParticles);
     }
 }

Any suggestions as to the problem? I'll post an update if I figure it out myself.

Thanks.

Comment
Add comment · Show 2
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 Lttldude · Apr 17, 2012 at 03:31 PM 0
Share

Were you able to get it to work?

avatar image graham · Apr 17, 2012 at 08:25 PM 0
Share

Yup, just been busy the last few days - thanks!

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Lttldude · Apr 15, 2012 at 09:02 PM

Your code is all good, except you didn't save the changed particle back to the array so it could be set back to the ParticleSystem.

 var particle = particles[i];
 particle.velocity = particle.velocity.normalized * mParticleSpeed;
 particles[i] = particle;
 
 OR
 
 particle[i].velocity = particle[i].velocity.normalized * mParticleSpeed;

Also, you are probably already aware of the mUpdateParticleSpeed variable, but as the code is written now, this will only affect particles that have already been emitted. If they are starting to emit on play, then none will be affected because it will only run for one frame when no particles are emitted. I emitted that whole conditional statement to make sure the code worked.

  • Josh

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 graham · Apr 17, 2012 at 08:24 PM 0
Share

Ah, of course - the particle is a struct not a class!

As for new particles, I have code to adjust the speed, I just didn't post it for clarity.

Thanks for spotting my mistake!

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

Setting the position of particles in a (shuriken) ParticleSystem 3 Answers

Scale Shuriken Particle System with Parent Transform 5 Answers

Particles emmiting all over the shape, is it possible make them spawn gradually from a set point? 0 Answers

PS Custom Vertex Streams to Particle Trail 0 Answers

How can I create a particle 'vortex' or implosion using Shuriken? 2 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