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

Bug Particles with collisions slip/glitch through corners of edge Collider

Discussion in 'Physics' started by DragonCoder, May 22, 2020.

  1. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,677
    Hello Community,

    despite using Collision Quality: High, my particles sometimes slip through the corners of a world that is made of 2D Edge-Colliders (am talking of a single collider with many segments).

    The ratio is about one of maybe 50 particles slip through but that is quite an annoyance. Neither a larger edge collider radius, nor increasing the particle collision radius helped. I know that it is the corners because a simple, horizontal edge does never allow any particle to slip through.

    Have found this thread that mentions a similar issue: https://answers.unity.com/questions/1315001/intersecting-edge-colliders-cause-particles-to-pas.html
    Is there still no solution and is this truly not a bug? Mind you, unlike in that thread, I am using the "High" quality setting where the documentation does not say it might miss collisions.

    Any ideas?
    Huge thanks in advance!
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,319
    An image would help because I don't know what you mean by a "corner". Two EdgeCollider2D put together do not form a continuous surface in the same way two BoxCollider2D wouldn't. Overlapping the start/end points on an EdgeCollider2D also doesn't make that a closed shape. In 2020.1 we introduced the ability to specify adjacent start/end points to EdgeCollider2D which allows you to specify the virtual edge adjacent to the start/end allowing EdgeCollider2D to effectively be joined or the start/end of a single EdgeCollider2D to be connected together.

    In the end, it's not the physics system handling particles. The particle system is a user of it like yourself and it has a pretty simple circle-cast query going on for each particle i.e. cast -> move to contact point -> cast move to contact point etc.

    to reduce my guessing, I'd need an image of what exactly you mean here for edge(s) though.

    EDIT: There isn't a high/low quality CircleCast in 2D physics so I'm not sure what it does in the particle system but it won't affect "collision quality" as there is no such thing.
     
  3. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,677
    Thank you kindly for answering!

    Am aware of that and I meant the corners between two segments of the same collider.
    Here an image where I have added a line renderer that gets exactly the same consecutive vectors as the collider.

    Particles Slipping.PNG


    Particles Slipping2.PNG

    What this shows is a single collider as well as a single line renderer. Notice the particles (intended to be bubbles one day). There are about 300 in the scene there and some have slipped through the line.
    The collision scale is not right yet, that's why there is such a large distance between the line and the bubbles that have successfully stopped by the line.

    The docu says:
    "High:
    When Collision Quality is set to High, collisions always use the physics system for detecting the collision results. This is the most resource-intensive option, but also the most accurate.

    Medium (Static Colliders):
    When Collision Quality is set to Medium (Static Colliders), collisions use a grid of voxels to cache previous collisions, for faster re-use in later frames."
    So with High, I am right to expect similarly reliable collisions as with rigid bodies of some sort, or not?

    By the way, I had the thought it could be the single applied force that causes this, but even reducing that to 0.1 (and the velocity drag with it) made no difference.

    An odd phenomenon is that the longer I wait, the more of the particles that came to a halt, suddenly slip through. And they slip through in waves somehow. As if there were force building up until they pass the barrier. They don't pass the barrier abruptly to snap to the other side but just phase through at the speed assigned by the force (as if the collider weren't there anymore).
     
    Last edited: May 22, 2020
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,319
    Well as I say, this is the particle system not the physics system so I have no idea.

    It effectively uses Physics2D.CircleCast (for 2D) and Physics.SphereCast (for 3D) but I don't have any bug reports that this penetrates through segments on an edge-chain so I'm just not sure. In the end though, particle movement isn't like a continuous collision detection and they only have a basic reponse that the particle system handles. It doesn't make it equivalent to what (say) a 2D collider would do with its solver that solves multiple contacts and can use continuous collision detection to ensure no tunnelling.

    I am surprised though that using an edge-radius on the EdgeCollider2D doesn't stop this. That would suggest something VERY odd going on with particles.
     
  5. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,677
    Hmm, strange. Note the last paragraph I added.

    Another thought however, my world is scaled quite large. The coordinates of the screenshot are at y = -3800
    I heard that large numbers can cause inaccuracies but am I in that range already?
    Did scale it down for testing purposes a few weeks ago when I noticed this the first time, but there was no change. Only scaled down to 1/10 though.

    Guess if nothing helps, I will make a separate project to examine the issue exactly and form a bugreport if I can reproduce it there. Maybe I can find out the circumstances more accurately.

    There was no difference in this regard between 2019.3 and the current alpha by the way.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,319
    Not being a particle dev I cannot really give you answers. If you're asking if a position of -3800 means 2D physics starts breaking down then the answer is no. Small inaccuracies like that are not going to stop circle-cast working. This is especially true if you're setting an edge-radius because then each edge acts like a capsule.

    A bug report is the only thing that'll probably help but again, this should be targetted to the particle system.
     
  7. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,677
    Have tried with larger edge radius without a difference in this regard sadly.
    Alright then, thank you for your help. There is no forum category where particle topics fit better in, is there?
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,319
    No unfortunately which is why particle stuff gets posted everywhere. :(
     
  9. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,677
    Had no issue reproducing the problem in a minimalistic sample. Have filed a bug report now.
     
    MelvMay likes this.
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,319
    Thanks!
     
  11. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,677
    Sadly my ticket got closed after the first answer: https://fogbugz.unity3d.com/default.asp?1249794_vati9kdjv4uv9oe9
    What I understand from that, is that the docu is quite confusing in the way it separates the "high" quality setting from "mid and low".
    Apparently the sentence "This is an approximation, so some missed collisions might occur." applies to all three types of collision and not only to the voxel-based type (although voxels are mentioned right in the same line).

    Very unfortunate because that makes the particles engine less powerful in my opinion and not suited at all for a case where every particle matters in some way.
    Guess I'll need a performance consuming workaround for my case...

    Here the minimal sample in case someone else wants to try this: https://www.dropbox.com/s/jy5cjgie9wudmfy/ParticlePhysicsBug.zip?dl=0
     
  12. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,677
    So fiddling a bit around with it, I did find a workaround that is at least not hard to implement:
    Just double each position/point of the collider and shift that second point along the y axis by 0.01f or more.
    For whatever reason, this perfectly fixes the issue.
    No particle slips anymore. It even works with tiny edge- and particle-diameters.
    Note that if you do that in my example, the attached line renderer does not like it and shows a weird shape, but the edge collider seems to be correct and you will not really notice those additional vertices affecting the physics behavior aside of fixing the problem.

    So yeah, with twice the collision vertices, you can avoid the issue I guess. Honestly this does confirm to me that this all is unintended behavior.

    Also by the way, I realized at least on a quick attempt, I am not able to reproduce this issue on the X axis. Particles pushed only horizontally, do not slip through apparently.

    EDIT:
    How nice, the devs have listened to my mail reply to the ticket and it is under investigation after all! :)
    https://issuetracker.unity3d.com/is...-colliders-points-when-collision-quality-high
     
    Last edited: Jun 1, 2020