Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Particle system to visualise wind – Vector Field

Discussion in 'General Discussion' started by aaro_murphy, Jul 5, 2020.

  1. aaro_murphy

    aaro_murphy

    Joined:
    Jul 5, 2020
    Posts:
    5
    Hi, maybe someone can help.
    I am trying to use a particle system around a character/creature for visualising wind. When wind hits the creature, it wants to disintegrate and parts of it fall apart.

    Unity's particle system can draw these 'streaks' where particles move and leave a trail. I was experimenting with it a bit, but ran into the issue not finding a way to apply custom forces to a particle. There is a 3d texture you can set with a 'vector field' in it. Which is similar, but a bit harder. Wish there was a simple way to just say 'add a force to particle 10' or something. But it wants this 'vector field' 3d texture. Perhaps someone has experience with this?

    How to have a custom wind or 'force field' effect particles in Unity3d?

    Thanks,
    Aaro
     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,509
    Particle systems do have an External Forces Module which works with Particle Force Fields. I don't know how well they'll work for your specific case, but that's where I'd start. They're pretty flexible.

    Another possibility is a custom script which modifies particle velocity. From memory you need to copy the whole particle buffer, but from there you can directly modify properties of each particle. Typically you'd want to avoid this approach if possible, though, as I suspect it'll be much slower than using built-in functionality.
     
  3. aaro_murphy

    aaro_murphy

    Joined:
    Jul 5, 2020
    Posts:
    5
    Thanks, I will try this and see if I get the results wanted
     
  4. Marcel303

    Marcel303

    Joined:
    Jan 26, 2013
    Posts:
    2
    Hi angrypenguin,

    (I'm working together on this with Aaro)

    Thanks for your answer. The copying over of the entire particle buffer seems inefficient, but certainly something to look into (given what we're trying to archive).

    The 'problem' we are facing, is that we are using a custom 'wind zone' which basically covers the entire scene. It has some custom behaviors specific to turbulence and how the wind evolves over time. The wind also affects each and every rigid body in our scene, and we want to use particles to visualize how the wind is affecting them locally, near our objects.

    Afaik the bult-in WindZone component doesn't have a way to either 1) make them affect rigid bodies or 2) have some method to sample the wind force vector given a location (x, y, z). This makes it so we can't use them for affecting rigid bodies. Besides the desire for a custom behavior of the wind, this also reduces their usefulness.

    We also looked at using the volume texture approach a bit, but since they would be bounded to the volume of the texture (instead of infinite) they're a bit of a hassle to use. We'd have to construct a custom volume for each particle system, update it each frame given the current time, wind behavior and the location of the particle system, etc. Perhaps this is what we'll end up doing, but seems like there should be an easier way (if less efficient for huge particle counts).
     
  5. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,323
    If you have custom behavior, then you'll need to control particles directly via a script.

    To have particles affect rigidbodies, you'll need to provide this method:
    https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnParticleCollision.html
     
  6. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,444
  7. Marcel303

    Marcel303

    Joined:
    Jan 26, 2013
    Posts:
    2
    Hi all,

    Than you for your tips and advice!

    I tried the job system approach, but I think it needs an experimental version of Unity. Or perhaps the example code is just outdated. Perhaps (if I ever get back to this), I will try to use the job system version. But for now, I got things working using GetParticles/SetParticles. It's a bit unfortunate that it copies over the entire particle buffer, but it seems not to affect frame time too much. :)

    Again thanks for your help!
     
    angrypenguin likes this.