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
1
Question by Malveka · Sep 06, 2017 at 06:32 PM · particlesvelocityparticlesystem

How does particle.velocity relate to the particle's actual velocity?

This question is about Shuriken particle systems. Based on my experiments it appears that the velocity property of a ParticleSystem.Particle object only reflects the constant Start Speed from the Main Particle System module, and does not account for any velocity changes from other modules. For example, here the start speed is set to 1:

alt text

Also, the system includes a Velocity Over Lifetime setting like so:

alt text

I use GetParticles() on the system in the Update() method and print the velocity, but the result is always just the velocity set by the Start Speed value, though I can clearly see the particles moving at different rates.

 velocity=(0.0, 1.0, 0.0)
 UnityEngine.MonoBehaviour:print(Object)

Is this the expected result? If so, is there any way to get the actual velocity for a given particle at any moment?

For other particle properties like size and color there are the GetCurrentSize() and GetCurrentColor() methods. Also, those properties are named startSize and startColor, making it clear that they are not necessarily the current value over the lifetime of the particle. I assumed that since velocity was simply called "velocity" and that since there is no GetCurrentVelocity(), that it contained the actual current value. But it appears this is not the case?

Thanks for your help!

part-system-1.png (24.9 kB)
part-system-2.png (12.9 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

2 Replies

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

Answer by richardkettlewell · Sep 07, 2017 at 08:32 AM

Hi Malveka,

We store 2 types of velocity per particle:

  • persistent velocity

  • animated velocity

The persistent velocity persists across frames. eg the Force module applies a force, this gets applied to the velocity, and then that velocity is remembered between frames. Another great example of this is Start Velocity. It is applied once at the start, and remembered afterwards on each frame.

The animated velocity is used for non-physics effects (noise, velocity over lifetime, etc). This velocity is not remembered across frames, because these modules calculate a new velocity value each frame.

Unfortunately, the script only allows you to access the persistent velocity, and not the animated velocity. I will look at adding an accessor for this in a future version.

Until then, if you are using a JIT platform, you may be able to use Reflection to access this "secret" property. See https://stackoverflow.com/questions/95910/find-a-private-field-with-reflection

Something like:

 var prop = particle.GetType().GetField("m_AnimatedVelocity", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
 prop.SetValue(particle, "new value");

This will not work on AOT platforms (eg Consoles, or Android with Mono), but it will work on JIT platforms (eg PC)

Good luck!

Comment
Add comment · Show 6 · 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 Malveka · Sep 07, 2017 at 06:03 PM 0
Share

Thanks Richard! That's very helpful. $$anonymous$$nowing that there are two different velocity values goes a long way towards enabling me to make sense of the behavior I've been seeing. :^)

Does the animated velocity incorporate persistent velocity? Or do the persistent and animated need to be combined in some way to get the actual velocity?

And, if I can sneak in one more question... What other particle properties have the same implementation (i.e. persistent and animated values)? AngularVelocity? AngularVelocity3D?

avatar image richardkettlewell ♦♦ · Sep 07, 2017 at 06:46 PM 0
Share

Just add Velocity to animatedVelocity to get the total. I've added some script properties for this today :)

We don't have any other properties that are split like this.

avatar image Malveka richardkettlewell ♦♦ · Sep 08, 2017 at 07:12 PM 0
Share

Excellent! This information is so helpful. Once again, thank you! Looking forward to when those properties are available. :^)

avatar image Artifact-Jesse · Nov 20, 2018 at 07:46 PM 0
Share

Any update on being able to modify particle.animatedVelocity? I'm trying to change a particle's direction after it has been created using particle.velocity and I'm not having any luck...

avatar image richardkettlewell ♦♦ Artifact-Jesse · Nov 21, 2018 at 09:35 AM 0
Share

Hi, the only update is that it's not trivial to make it writable, because it is reset every frame, and the order of the simulation doesn't make it usable in script:

  • Native update (build animatedVelocity)

  • Native update (apply animatedVelocity and reset it to zero)

  • Script Update (too late, animatedVelocity was already calculated and applied)

  • Script LateUpdate (far too late!)

So for now it will only be readable.

Changing the direction of a particle after birth is possible unless you are overwriting it with the Velocity over Lifetime module.

avatar image Artifact-Jesse richardkettlewell ♦♦ · Nov 21, 2018 at 06:06 PM 0
Share

Interesting... thanks for the update! That's actually pretty helpful in understanding how the velocities relate to one another...

As an aside, for my purposes, I didn't need to modify animated velocity. I think my problem was unrelated to velocity in general (I'll mention it here in case someone finds it helpful). After many, many hours of trial and error and reading forum posts... basically I needed to use ParticleSystem.Emit(emitParams, count) to create my particles manually and set their position if I wanted to also modify their Particle.velocity at will. Previously I was trying to recreate the entire array every time it updated (as per Live Training 11-decals section), but it seemed like the system wasn't simulating, because even if I set their velocities they wouldn't move. $$anonymous$$uch better to let the ParticleSystem handle its own emissions with me giving it parameters as necessary.

Anyway, thanks again, @richardkettlewell for helping us understand this stuff more completely! If there's any way to recommend that someone do another, deeper set of Live Sessions on manually manipulating particles, that would be absolutely stellar. There are a lot of pitfalls and optimization tricks that are buried pretty deep in the internet.

Cheers!

avatar image
1

Answer by ifurkend · Sep 06, 2017 at 10:46 PM

Just very recently I have the same question and after few testing, Particle.velocity ignores (or its sum is calculated before) "velocity over lifetime", "inherit current velocity" and "noise". Other than these 3, "start speed", "gravity modifier", "limit velocity over lifetime", "inherit initial velocity", "force over lifetime" (randomized or not) and collision are all accounted to Particle.velocity. @Richardkettlewell or @karl_jones could shed some light, perhaps...

c.f. https://feedback.unity3d.com/suggestions/shuriken-particle-constantly-inherit-velocity-including-noise-of-sub-emitter-from-spawning-particle

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 Malveka · Sep 07, 2017 at 12:26 AM 0
Share

Thanks for the reply! I need to do some more tests. Also, the link to the forum thread is especially helpful since there are some Unity developers participating there.

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

73 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

Related Questions

Can you change the Velocity Over Lifetime of a Particle System using a Script? 3 Answers

How to make an effect in a particle system so that it is always behind the sphere? 1 Answer

How to control velocity of particles? 0 Answers

Particle Velocity Decay/Slow Down? 1 Answer

How is Limit Velocity Over Lifetime calculated? 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