Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

2D Physics + Particle Systems Collision

Discussion in '2D' started by Big_Pixel, Nov 13, 2013.

  1. Big_Pixel

    Big_Pixel

    Joined:
    Jul 5, 2013
    Posts:
    2
    Hi,

    Is it possible to get particles from a Particle System to collide and react to collisions with 2D colliders?

    Turning on World Collision with a particle system seems to allow it to collide with regular 3D colliders, but it doesn't seem to work with any of the 2D colliders. Is it intentional, or is there another setting for particle systems to enable 2D collision?

    Thanks for any help you can provide.
     
    Last edited: Nov 13, 2013
  2. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    Hi there!

    This is not currently supported but planned for a future release. Sorry! For now you'd need to use a bunch of existing primitive collider2D sprites.

    Will
     
  3. Big_Pixel

    Big_Pixel

    Joined:
    Jul 5, 2013
    Posts:
    2
    Hi Will,

    No problem, that's fine. Just checking in case we were missing something obvious in the settings.

    Cheers
     
  4. RazorSRam

    RazorSRam

    Joined:
    Dec 26, 2013
    Posts:
    2
    Hey guys,
    Any update on this issue ? Is it possible now to detect particle collisions on a 2D collider ?

    Thanks Regards,
    RazorSRam.
     
  5. perracolabs

    perracolabs

    Joined:
    Apr 3, 2014
    Posts:
    29
    Any update for particles 2d collision?
     
  6. DocMcShot

    DocMcShot

    Joined:
    Mar 18, 2014
    Posts:
    14
    Any update on this? Is it possible to detect particle collision in with 2d colliders? If not, is there any eta on when this functionality will be available?
     
  7. Ash-Blue

    Ash-Blue

    Joined:
    Aug 18, 2013
    Posts:
    102
    Would love to hear an update on this, working around Shuriken for a custom particle solution creates a horrible workflow. For all of us 2D users, this would make our lives 1,000,000x simpler.

    Really want to hear this is coming for Unity 5, would be kinda sad if it isn't (as I'm guessing its super simple to add a 2D collider option or a quick fix of some sort).
     
  8. fenadoruk

    fenadoruk

    Joined:
    Feb 14, 2015
    Posts:
    1
    Any updates on this issue?
     
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,326
    The idea is that this will go into the 5.x product cycle. That's all I know for now.
     
  10. flyingbanana

    flyingbanana

    Joined:
    Jan 28, 2014
    Posts:
    22
    Would be great if it'll come out soon!

    Meanwhile, are there any workarounds (other than changing all existing other things to 3D colliders or stop using the particle system)?
     
  11. amroc

    amroc

    Joined:
    Apr 8, 2014
    Posts:
    13
    Yes there is a workaround, you can process collisions manually using ParticleSystem.GetParticles and SetParticles to access the particles, doing a Physics2D.Raycast for each particle, then finally adjusting each particle's velocity if the raycast reports a desired hit. It works great, and doesn't perform badly at all.
     
  12. Outwizard

    Outwizard

    Joined:
    Jun 25, 2015
    Posts:
    22
    Last edited: Jun 25, 2015
  13. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    I have a working prototype of shuriken + box 2D. Hopefully to release it very soon!
     
    Gruguir and flyingbanana like this.
  14. charmandermon

    charmandermon

    Joined:
    Dec 4, 2011
    Posts:
    352
    any chance we could beta test it?
     
  15. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    Yes for sure! Coming out in the next alpha release, hopefully in a couple of weeks time!
     
    Deleted User likes this.
  16. danthekilla

    danthekilla

    Joined:
    Jun 14, 2015
    Posts:
    3
    Watching this thread.

    This is exactly what I need. Will you have a youtube video on how to use it also?

    Cannot wait.
     
  17. Deleted User

    Deleted User

    Guest

    Paul, from one Paul to another, thank you for doing this!

    It would make a huge difference to my game's look & feel with colliding particles.
     
  18. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    I will make on but it is dead simple. WHen the feature is out, you will have to go to the "Collision" module of shuriken, select "World" and choose between 2D and 3D. That's it!

    Some feedback if "Both" are needed would be great!
     
  19. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    Sure, i'd definitely use the 2d+3d particle collisions option, it would be a must, as there are many 2d/3d mixed games, including my projects.
     
  20. andrin2020

    andrin2020

    Joined:
    Mar 9, 2014
    Posts:
    29
    I am eagerly anticipating/waiting this feature. Using 3d colliders now and not liking the results I am getting
     
  21. Backward-pieS

    Backward-pieS

    Joined:
    Feb 7, 2013
    Posts:
    20
    ColossalPaul: Is there an email list or something I can sign up for to be notified the moment this feature is available? Would really speed up my workflow. :)
     
    Ash-Blue likes this.
  22. Ash-Blue

    Ash-Blue

    Joined:
    Aug 18, 2013
    Posts:
    102
    I too frequently think about how much easier this feature would make my life. Sign me up for a mailing list if there is one.
     
  23. boydbueno

    boydbueno

    Joined:
    Sep 9, 2015
    Posts:
    1
    I'm eagerly awaiting this feature.
     
  24. dzamani

    dzamani

    Joined:
    Feb 25, 2014
    Posts:
    122
    Hi there, according to Unity Roadmap, this feature will be available with Unity 5.3 (Dec 8, 2015).

    EDIT : Actually, I found a post with some videos where we see how it works (a little bit) : http://forum.unity3d.com/threads/2d-alpha-release-3.347722/
     
    Last edited: Sep 15, 2015
    andrew_fundscomein and Ash-Blue like this.
  25. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    Hey all, to provide some more detail on the upcoming 2D collision support, the initial version will be available from 5.3 Alpha 4, so those with access to alpha and beta builds will be able to try it out very soon.

    It will hook into the same OnParticleCollision callback that currently exists for 3D collisions, and we are currently working on modifying the ParticleCollisionEvent struct (used with GetCollisionEvents) so that you can access the Collider2D for 2D objects.

    It's also interesting to hear that you would like both 2D & 3D collisions at the same time!
     
    Too-Nerd-To-Die likes this.
  26. Eluem

    Eluem

    Joined:
    Apr 13, 2013
    Posts:
    57
    Excited to hear about when this will be coming to a stable release. I'm glad that it sounds like it's pretty close :D
     
  27. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    would quickly left the stable version, it is too early to use 5.3
     
  28. Magnumstar

    Magnumstar

    Joined:
    Oct 3, 2015
    Posts:
    304
    Confirmed 2D particle collisions are included in 5.3.2f build. Looks great!
     
    richardkettlewell likes this.
  29. PimajeXenja

    PimajeXenja

    Joined:
    Dec 31, 2014
    Posts:
    10
    The 2d particle collisions are great! I have a quick question though. Can particles be used as triggers? For instance, If I have some "icy wind" that occasionally blows in from the east, could I reduce character movement while player was colliding with the particles? Right now the wind particles just bounce off the player.
     
    tanoshimi likes this.
  30. Eluem

    Eluem

    Joined:
    Apr 13, 2013
    Posts:
    57
    It'd be better to use an Area Effector (http://docs.unity3d.com/Manual/class-AreaEffector2D.html) if you're working in 2D. If not, then you can create a collision box trigger and write code in it that mimics the functionality of an Area Effector which will apply a force to an object inside of it.

    Hope this helps.
     
    PimajeXenja and MoonJellyGames like this.
  31. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    We have a new Trigger Module coming in 5.4, which could be useful for this.

    In this use case, you would set up a collision volume around your player, attach it to the Trigger Module, and it can tell you how many particles are inside the volume, via a script callback similar to OnParticleCollision (it's called OnParticleTrigger).

    I would guess you could then use the particle count to slow down your player, or whatever behavior you desire.

    It's also possible to get the list of particles inside the volume, so maybe you could average their velocities together to get an overall "push" direction to apply to your character or something.

    Hope it helps!
     
  32. PimajeXenja

    PimajeXenja

    Joined:
    Dec 31, 2014
    Posts:
    10
    Thanks all! Both solutions are viable, I just have to use the method that works best for me.
     
  33. PimajeXenja

    PimajeXenja

    Joined:
    Dec 31, 2014
    Posts:
    10
    Quick question. I was looking around, admittedly not very thoroughly, and I didn't seem to find any references to scripting an effector. I would like to reverse an effector's effect through code. Is this possible? Or do I need two effectors, that affect two different layers, and a change layer group method on my player?
     
  34. Eluem

    Eluem

    Joined:
    Apr 13, 2013
    Posts:
    57
    I'm fairly certain you could just change the ForceMagnitude or ForceAngle... also if you wanted to do the whole two effector thing, you could put them in the same layer and toggle one on and the other off, rather than moving the object you want to effect into different layers.

    Another thing with multiple different layer definitions on a player object (which I use to handle i-frames for certain abilities): you can do this by having a child "Colliders" with children for each layer you want the object to be able to interact with and toggle them accordingly.

    In my game I have one for PlayerToHazards, PlayerToPlayers, PlayerToLowWalls and I can toggle these to allow the player to dodge through hazards or jump over walls (it's a top down game).

    Just some food for thought! Hope this helps :D
     
  35. tanoshimi

    tanoshimi

    Joined:
    May 21, 2013
    Posts:
    297
    Subscribing to this thread because I have *exactly* the same requirement :)

    When I saw 2d particle colliders had been introduced in 5.3, I excitedly rewrote an old custom particle system to use Shuriken instead, and all was going brilliantly until I realised there was no OnParticleCollision2D callback so they currently provide eye candy only :( I couldn't understand how the area effector would help, but I guess it's not long to wait til 5.4 now!

    One other question - particles don't currently seem to collide with other particles. Is this always going to be the case? Suppose I have one particle system of "icy shards" and one of "fiery sparks". Is it possible to detect when they collide to create "watery droplets/steamy particles"? Or should I stick with full blown gameobjects and collider2Ds for this kind of interaction?
     
  36. Eluem

    Eluem

    Joined:
    Apr 13, 2013
    Posts:
    57
    It depends on exactly what you're trying to do with the collision of these particles. In the example provided by PimajeXenja, if you don't need the exact collision of each particle to slow the player down, you can create a sort of "wind blowing towards you" effect by using an area effector to apply the force of the "wind" and keeping the particle system there for a visual representation only.

    If you're using the particle system to actually fire larger more significant projectiles.. or you're using it to attempt to create a very complex/accurate simulation of some sort, then this doesn't resolve your problem. It works well when the player would never be able to tell the difference... or when it would actually feel better to have a more controlled force rather than one that is fired off intermittently by each particle.


    The icy shards vs fiery sparks could be handled similarly. If the ice and fire could each be treated as single large objects with primitive colliders that use a particle effect to represent the area that they're taking up visually. When the two colliders touch, you can generate a steam object/particle effect. Depending on close the centers of the fire and ice objects are, you can increase the "intensity" of the steam and make it's effect get bigger.
     
    richardkettlewell and tanoshimi like this.
  37. Rainbooow

    Rainbooow

    Joined:
    Jan 26, 2016
    Posts:
    8
    Is there a way (from the collision editor if possible) with the current particle system to send collision messages (so that the OnParticleCollision methods are called), but without impacting the particles movement (so that the particles behaves as if there was no collision)?
    I tried playing with the bounce/dampen values, but I did not find a proper way to do it.
     
  38. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    You can do that with the Trigger Module in 5.4, using the OnParticleTrigger script function. I don't think it's possible in Unity 5.3 though.
     
  39. Rainbooow

    Rainbooow

    Joined:
    Jan 26, 2016
    Posts:
    8
    Thank you for your answer. I was indeed able to use the OnParticleTrigger script function with the 5.4 beta. However, it seems that there is no way from this function to be able to retrieve the object the particles collides with, you can only interact with the particles themselves.

    To be a bit more concrete, here is my use case : I am using the particle system to create a poison fog, that should hurt the players that go inside. Either I do it with the collision module, but then, the rotation of the poison particles is affected when a player goes inside (when the bounce value is at 0, it seems to stop the particle). Or, I use the trigger module, but I did not find a way to be able to retrieve the player gameObject so that I could adjust its health.

    Is the particle system not designed for that kind of use case, or am I using it wrong?
     
  40. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    I've just looked at our code, and it seems that you are correct. If you want to report a bug for this, we may be able to add support for it. My only concern is that it gets a bit unclear how to behave when particles are overlapping two trigger objects at the same time... which one should it report? I guess it would need to report all of them and pass an array into the callback?
     
  41. Rainbooow

    Rainbooow

    Joined:
    Jan 26, 2016
    Posts:
    8
    An array would solve the issue I guess.

    But I am not too sure what is the rational behind the design of the trigger module. If I understand well, this is primarly designed so that you can update the particles that triggered the collision with the trigger objects, not to update the trigger objects themselves. To be honest, I am not sure why you cannot nullify the bounce, change its direction, etc. in the collision module, and can only modify the value of the bounce. Lets say that instead of bouncing, you want the particle to continue its movement in the same direction, but slower. This seems to me to fit the collision module use case, but if I understand well, to do so, I would need to use the trigger module.
     
  42. dusteff

    dusteff

    Joined:
    Jan 7, 2022
    Posts:
    4
    An oldie but a goodie... I don't seem to see friction material / friction on individual particles still on unity YET you can use a Velocity over Time Curve and make it simulate friction to bring the Speed to 0 eventually. Works well in most applications.