Search Unity

How to constrain a particle system to within a rectangular area

Discussion in 'General Graphics' started by FuriantMedia, Dec 21, 2017.

  1. FuriantMedia

    FuriantMedia

    Joined:
    May 8, 2013
    Posts:
    9
    I'm trying to implement a means of keeping particles within a box in a UI menu. Generally, if you put a few balls in a box, closed the lid, then shook the box: that's the behavior I want, but only on the X and Y axes, as this is in a UI menu.

    Details

    In my UI screen I have a canvas, and in that canvas is a game object (I'll call this the container) with a rect transform. It represent the title bar of that screen. As a child of the container I have a particle system (and some other stuff like text).

    The particle system emits from an edge shape on the left, throwing particles toward a point on the right. The particles travel mostly on X axis, but over their lifetime they may gain slight velocity on the Y axis.

    I want to constrain the position of the particles to within the container's rect bounds. When the particles hit the bounds, they should bounce and continue their travel. Like balls in a box.
    I've played with collision and masking, and have spent the past 2 days searching for solutions, and I've come up empty. This seems like it should be simple.

    The closest I've gotten has been using Plane colliders, but no matter where I position the plane(s), the system always collides with it on the left first, and then bounces on top of it -- they don't act like planes, no matter how I rotate them; they act like cubes.

    I also messed around with the emit shapes, but none seem to provide the behavior I want. I tried using World collision but it didn't help, though I may be missing something.

    I can't seem to define a bounding area for the particles to collide within. Any help would be appreciated.
     
    Last edited: Dec 21, 2017
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    I suggest setting the Collision Module mode to Planes, and create 4 GameObjects to define the edges of the box.
     
  3. FuriantMedia

    FuriantMedia

    Joined:
    May 8, 2013
    Posts:
    9
    As I mentioned, I've tried using Planes. I only used 2 to define the Top and Bottom, but no matter how I scale/rotate/position the planes, the system won't emit particles between the planes; instead it treats them like a cube and collides immediately at the left edge, spills over the top, then bounces on top of it. It does this even with just one plane.

     
    Last edited: Dec 21, 2017
  4. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    I interpreted “plane collider” as a physics primitive, not the planes mode within the particle system.

    The Planes are single sided. What you describe sounds like the plane should be rotated 180 degrees. Particles may only exist on 1 side of the plane.
     
    FuriantMedia likes this.
  5. FuriantMedia

    FuriantMedia

    Joined:
    May 8, 2013
    Posts:
    9
    The 180 rotation did the trick, once I also set the Height of the each plane to 0 (for some reason). Just a thought: it would be really nice to have an option to just tell a particle system to collide within its own rect bounds.

    Thanks for the help!
     
    richardkettlewell likes this.