• 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
1
Question by catwoman · Nov 22, 2012 at 03:49 PM · velocitysystemparticle

Particle System, change the velocity by script

How could I change the "Velocity over Lifetime" setting of a Partycle System using a C# script?

alt text

Thank you guys!

immagine.png (6.0 kB)
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 catwoman · Nov 22, 2012 at 08:34 PM 0
Share

any idea? thanks

avatar image GerryM · Nov 22, 2012 at 08:38 PM 1
Share

Check here

1 Reply

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

Answer by GerryM · Nov 24, 2012 at 09:11 AM

You need to set the particles, too. In case you want to change the velocity according to lifetime, try something like this:

 void LateUpdate () {
         
         ParticleSystem.Particle[] p = new ParticleSystem.Particle[particleSystem.particleCount+1];
         int l = particleSystem.GetParticles(p);
         
         int i = 0;
         while (i < l) {
             p[i].velocity = new Vector3(0, p[i].lifetime / p[i].startLifetime * 10F, 0);
             i++;
         }
  
         particleSystem.SetParticles(p, l);    
         
     }
Comment
Add comment · Show 4 · 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 catwoman · Nov 25, 2012 at 09:38 AM 0
Share

well... I still cannot understand exactly how does it work...

For example in my starting situation, velocity over lifetime is X=50, Y, 0, Z= 0, and the particles move along the X axis.

When a particular event occur I'd like that the particles move along the Y axis, and this can be done by change the Inspector property "Velocity over lifetime" at X = 0, Y= 50, Z= 0.

I'd like to control this behavior with a C# script.

It would be enough to change the "Veloity over lifetime" property, but it seems this is not possible.

Your script change the velocity of the particles but in a strange way...

So for example if I write:

 p[i].velocity = new Vector3 (0, 50, 0)

the particles don't move along the Y axis...

Thanks for your help...

avatar image GerryM · Nov 25, 2012 at 11:48 AM 0
Share

It's tricky, you need to change (in the inspector) from local to world space to have y up. Or you do rotate the particle system.

avatar image catwoman · Nov 25, 2012 at 04:14 PM 0
Share

hmmm, I've realised what was the problem:

I've set in the inspector a velocity over lifetime of (50, 0, 0) and the particles move along the X axis.

If in a script I add the code:

p[i].velocity = new Vector3(0, 50, 0)

the particles won't move vertically along the Y axis, because they already have a X=50... So they will move at 45° degrees.

hmmm, so now I'm not sure if this is the best way to ROTATE my particles along its origin...

avatar image catwoman · Nov 25, 2012 at 04:48 PM 0
Share

oh, in order to rotate a particle system, it's enough to turn the object the particle is attached with... like an empty object for example....

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

How to create particle system on a collision? 1 Answer

Script to scale particle system 2 Answers

enable / disable particle system 1 Answer

Creating a particle system that uses 1 draw call 0 Answers

Can you still not change the Velocity of spawned particles? 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