Search Unity

Rain goes splash

Discussion in 'Scripting' started by antenna-tree, Mar 6, 2007.

  1. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    I'm trying to use the World Particle Collder to make some splashing rain drops by instantiating a texture where the particles collide on the ground using ContactPoint but I can't get the Collision to trigger. I've turned on "Send Collision Message" on the particle but nothing happens.

    I've tried both OnCollisionEnter and OnParticleCollision but neither one is working. Any hints for a poor scripting simpleton?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    OnParticleCollision takes a Collider, not a Collision type parameter; my guess is that's where your problem is. And a fundamental problem at that -- a collider by itself doesn't have enough data to tell you the point at which a particle collided with it. :( (I tried to do the same thing...)
     
  3. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    Create your own particle system and use the built-in particle system just to render, so you have all the information needed for that.

    Well, i know you can take every single particle at the time and take it's position, if you are intersecting with a plane, then will be easy to know where it hits the plane by:

    Code (csharp):
    1. if ( particle.position.y < plane.position.y )
    2. {
    3.    destroyParticle ();
    4.    createRainSpotAt (particle.position);
    5. }
    6.  
    Checking only the Y attribute if you make the particle system a child of the plane i think.

     
  4. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    On my research, here is an scene with a rain effect, the object named Splash is the one positioned at the position of the particle colliding (or whom Y is less that the Y of the plane explicitly given on the editor). Some particles are ignored i don't know why, maybe i should find the most lower particle but that would be more computationally expensive.

    Anyway, i created a light to see where the particle collides with the plane, and named it Splash. Then I thought that positioning another particle system would be a better approach (debris) to the rain effect, but changing the transform.position of that particle system (that i named Splash2 to disable it) makes my unity to crash. Im about to send the bug report, can someone check it too ? you have to rename the light Splash to anything else and rename the particle system Splash2 to Splash.

    Here is the scene

    Omar Rojo
     

    Attached Files:

  5. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Thanks Omar, that's a good way to fake this effect on a flat plane and it helped me to get a little closer with using OnParticleCollision. Unfortunately, ParticleEmitter.particles[index].position doesn't always grab the particle at the position of the flat plane (if you look at you're example from the side you'll see the light move up/down in Y).

    I tweaked your solution a little bit but using OnParticleCollision to get the position of the particle on sloped terrain...

    Code (csharp):
    1. var rainSplash : GameObject;
    2.  
    3. function OnParticleCollision ()
    4. {
    5.     var particles = particleEmitter.particles;
    6.     Instantiate (rainSplash, particles[0].position, Quaternion.identity);
    7. }
    The only problem with this is that I can only have one particle at once shooting down really fast to gat a proper indexing of the particles[].position. I then have a second particle emitter that makes more rain drops. OTEE, would it be possible to get particle collision cantact info in the future?

    Example of how this looks so far.
     
  6. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Looks great man!
    AC
     
  7. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    In my script you can change the mPlaneY value to suit your needs, well i don't know, neither of the solutions will be as good as getting the particle that collides with the object, so OTEE.. let's work :D

    Omar Rojo
     
  8. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    The best rain effect I've seen outside a tech demo was the first level of Metal Gear Solid 2 on the PS2. They faked it:

    They didn't bother about the individual rain drops, because in real life, you can't really connect each falling raindrop with a speciic splash.

    Instead they placed small particle-like polygons on the upwards-facing parts of their meshes (yeah, also on skinned characters), and then used a vertex program to cycle UVs so only 20% were visible at a time. It looked totally random and gave the feeling of a diluge coming down from above.

    In pseudocode:
    go over all meshes in the scene
    shoot a bunch of rays downwards against each of them
    Where the rays intersect, add a quad to a custom mesh. This quad shold have a UV space that is, say, 1/8th of the full texture space on each axis (think of a tiled particle image from a particle system).

    the trick to make it work completely is to extrude the splash particles in a vertex program. I'll be happy to help with that.

    On a side note, I noticed that ATI released a paper on the various parts that made up their fantastic rainy street demo. a lot of it is very hairy, but it might be worth skimming for inspiration....
     
  9. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Gears of War handled rain really well. I just fired it up again to check how they did it.

    They don't bother with rain interaction with the characters themselves when you are standing out in the open, and they also don't do splashes on the ground. What they do is animate the UV coords of a spec/gloss map (possible refraction too, but I doubt it). (EDIT: They do this on the ground, trees, just about everything except the characters.)

    When a character walks into a stream of water like you would get through a hole in a roof, or from a downspout, they instantiate a particle system at the point with what looks basically like cloud-like particles with a refraction shader. Looks really good, and because of the UV animation on the ground, you don't notice that there aren't any individual splashes.

    Mind you, this was also at night, so I don't know how it would look in the daylight.

    And I can't for the life of me find a screenshot!

    (EDIT2: Splintercell 3: Chaos Theory did a similar effect with animated spec map UVs)

    -Jeremy
     
  10. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Interesting ideas everyone. I'd especially like to see Nich's solution as a Unity demo.

    This is for a really cartoony world though so I do kinda want that one to one ratio of raindrop to splash instead of a deluge effect. Raycasts were my next idea, but I couldn't resist first trying to do it with particles because it seemed like it would be simple... so much for that :wink:

    [Edit] Nich, do you have a link to that ATI rain demo?
     
  11. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    I think using Raycasts will work well enough for my purposes... here's an example.
     
  12. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
  13. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Hi guys (my first post in the forums :D )

    I thought of another way of doing it with the ParticleCollider. I set the Collision Energy Loss to be a large negative value, so that when the particle collides, it ends up with an energy greater than anything it could have gotten from the emitter.

    I then run a script, which replaces all high-energy particles with nice little explosions. (Oh yes, forgot to mention. I was not actually interested in rain right now)

    Demo here
    http://proglet.com/software/Unity/Particles/ParticleCollision.html

    and javascript below
     

    Attached Files:

  14. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    Very nice cblarsen, very very nice indeed, so you can catch up the high energy particles and even more than one in a strike.

    Congratulations >D

    Omar Rojo
     
  15. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Yeah, I think it would be ok for rain. The only thing you cannot do is have information about the particle and information about the object it collides with in the same script.

    In my script you know where the particle collided, its velocity and so on.

    In the OnParticleCollision function you know which object was hit, but nothing about the particle that did it.

    However my main complaint about the particle system is that it is way too fun to play with.
     
  16. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    Particle systems needs a mayor upgrade/redesign since they cover a lot of stuff on a game.

    Hope in the next Unity version we'll see a very powerful PS that allows us to do anything.. and more

    Omar Rojo
     
  17. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    I finally bought this game for the sole purpose of checking out the rain you were talking about ($7 for MGS2 used, well worth it for just a study... I'll never play through it because I find stealth games seriously annoying)). The rain on that first level is indeed impressive though.

    Would you mind breaking down the process of getting such an effect in Unity? To me it looks like there are 3 things going on... a particle system right in front of the camera creating rain blowing in all directions, another particle system creating rain falling in a downward direction, and then the most important part of the splashes happening on all the upward facing geometry. It looks like a lot of polys are necessary to create the splash effect... you think it's just cycling through a texture using offest? Damn I love this stuff... there's a thousand and one solutions to every problem.
     
  18. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Wow I just reread that MGS Breakdown..Its just as cool reading it the third time round.

    Has anyone got some more recent work they wouldnt mind sharing? I've spent a couple of days fiddling with OnParticleCollision() but havent really got anything to show for it. Im imagining a plane above the player that follows the player and emits particles...Which is dandy, but if anyone has an entry point for the raycasting approach- that would be great. I imagine you would raycast from vertex points? Or surface normals?

    Thanks again
    AC
     
  19. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    LOL Heisenberg!!! Ha ha ha!
     
  20. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    I spent some time with cblarsens script recently but it always instantiated the new particle systems quite some distance above the ground. Has anyone whos tried this found this and also the reason why?

    I dont get the raycasting approach.

    I wonder if the UT guys are looking at expanding the OnParticleCollision functionality? Basically the trouble starts when you try and match

    function OnParticleCollision (other : GameObject) {}

    with

    function OnCollisionEnter(collision : Collision) {

    Which kind of seem like 2 different dialects. First being collision, second being collider. The question is how do you match up parameters like collision and collider?

    Hopefully some has some interesting insight...

    Cheers
    AC
     
  21. matanuki

    matanuki

    Joined:
    Nov 4, 2009
    Posts:
    1
    Hey all! This is my first post here.

    Sorry to bump an old thread, but I felt compelled to register because I was having trouble making use of the World Particle Collider and found cblarsen's post:

    And his method worked beautifully. I have this little planetoid where things grow when the user clicks on it, and I wanted to have the each of the growing elements drop particle-based "spores" that would seed new elements themselves. Here's a look at the prototype.

    So like I said, using cblarsen's method of blasting the particles' energy level then screening them works well, but I'm wondering if there's any less roundabout way of doing this? It looks like OnParticleCollision() still just reports the collider without giving any info on the particle that did the colliding.
     
  22. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Is it easier just to choose randomly where you want the spores to land and then animate them to their destination?