Search Unity

Circle collisions, no longer acting as accurate as in Previous Unity Versions

Discussion in 'Physics' started by skinnysimmons, Dec 4, 2015.

  1. skinnysimmons

    skinnysimmons

    Joined:
    Oct 6, 2012
    Posts:
    20
    Hello all, thanks for reading!

    My game's collisions were working fine before updating to 5.2.3 (not exactly sure which version it was at before... but it would have been active at Feb 2015)

    Regardless, now my 2D character (with a circle collider, colliding with other circle colliders) seems to go past the boundaries of the circles quite often, (about 1/4 of the way into each circle) when it used to not do that at all... Any ideas as to what might have changed in the versions from Feb 2015 to 5.2.3 that might have them computing differently?

    Thanks all!
     
  2. ButcherBolzi

    ButcherBolzi

    Joined:
    May 31, 2014
    Posts:
    17
    I also discovered that Unity 5.2.3 2d physics not working properly. If you'll have collision detection set to continuous, then system does not always call OnCollisionEnter2D, only occasionally.
    Also I'll have other problem in game where I modify ground collider (breaking a world) after collision inside OnCollisionEnter2D method, but now it seems that there is no always collision impact and object go much deeper in the ground. For this other case collision detection is set to discrete, but there is joints in the object.

    Edit: With a quick look, it seems that 5.2.3p2 fix all those problems!
     
    Last edited: Dec 4, 2015
  3. ButcherBolzi

    ButcherBolzi

    Joined:
    May 31, 2014
    Posts:
    17
    More test with a version 5.2.3p2 and now it seems that OnTriggerEnter2D called only occasionally.

    Edit: More test. Trigger start with OnTriggerStay2D and exit with OnTriggerExit2D, but only sometimes OnTriggerEnter2D is called.
     
    Last edited: Dec 4, 2015
  4. skinnysimmons

    skinnysimmons

    Joined:
    Oct 6, 2012
    Posts:
    20
    Here's an image of when the collision usually occurs. the BLUE arrows show the collision circle around the bubble and the fish that SHOULD be colliding. The Red arrow is pointing to a collision circle that is used for hit detection from a touch, so, no collision with other objects in scene is necessary, please ignore that.

    We have looked into discrete vs continuous types, and the collision layers.

    Thanks again!
     

    Attached Files:

  5. lavz24

    lavz24

    Joined:
    Mar 14, 2013
    Posts:
    45
    Hi I have the same problem, After upgrade 5.2.3f1 the physics doesnt work anymore. I have to 4.2.2p3 and Its work well
     
  6. skinnysimmons

    skinnysimmons

    Joined:
    Oct 6, 2012
    Posts:
    20
    ... seems kinda like a big deal, no? anyone?
     
    Last edited: Dec 7, 2015
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    The physics system doesn't work anymore? Really? I think that would've been made a priority. There was a bug which affected continuous collision callbacks (the collision still occur, just that the callback didn't happen) when a collision started/stopped during a single update but surely this isn't what you mean when you say 'the physics system not working anymore'? Besides, it was fixed in 5.2.3p2 as mentioned in the previous post but you read that and tried it right? If not, could you please provide more info.
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    I've not seen any bug reports like this. Have you tried 5.2.3p2? If not, can you submit a bug report and provide me with the case number so I can investigate for you?
     
  9. OnTopStudios

    OnTopStudios

    Joined:
    Aug 19, 2013
    Posts:
    44
    Hi,

    On our project we are using v5.2.3p2 and the bug still exists.
     
  10. skinnysimmons

    skinnysimmons

    Joined:
    Oct 6, 2012
    Posts:
    20
    It still exists in my project at 5.2.3p2 as well
     
  11. skinnysimmons

    skinnysimmons

    Joined:
    Oct 6, 2012
    Posts:
    20
    I submitted some info via Unity's Help>Report Bug menu, however it did not give me a number to attach here.
     
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    Which bug? Some circle collision bug?

    I didn't think that would change it TBH as it doesn't relate to what you seem to be reporting. Know that the bug I'm referring to didn't affect collisions themselves, just the reporting.

    Following the Bug Reporting guide, you should receive a confirmation email.

    EDIT: I did a quick search on the system for a title similar to this thread title but couldn't find it.
     
    Last edited: Dec 8, 2015
  13. jackburf

    jackburf

    Joined:
    May 7, 2013
    Posts:
    9
    Hey just to let you know I'm also experiencing this issue. Circle collider OnTriggerEnter function gets called very, very rarely. using patch 5.2.3p2 on Mac. Happened as soon as I updated to the latest patch.
     
  14. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    How do you know this is the same issue? I have yet to see a bug report and the original poster has said nothing about using circle colliders set as triggers and getting an OnTriggerEnter called rarely.

    Let's stop the 'me too' until we get some real information otherwise these threads become confusing. Got a problem; please post a bug report and let me know. Send me a private message or create another thread please.
     
  15. skinnysimmons

    skinnysimmons

    Joined:
    Oct 6, 2012
    Posts:
    20
    Sorry for the way this thread is unfolding, I really appreciate the help and attention you are offering
    Here is a bug report # 751578
    I'm using this as the only code in for collisions. on the ball, as you will see in the report, but here for quick reference:

    Code (CSharp):
    1. void OnCollisionEnter (Collision collision){
    2.         if (collision.gameObject.tag == "thumb") {
    3.             this.GetComponent<Rigidbody> ().AddForce (Vector3.up * upSpeed);
    4.         }

    This is newest report # (based off a simpler project that shows the same issue), this is the number I received for the first report (751496) which can be deleted, as it has less information bundled with it.
     
  16. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    Hey, no need to apologize, I just want to keep the thread sane.

    The above code is 3D physics, not 2D physics and so is your case 751578. I work on 2D physics not 3D physics. Which do you have a problem with?

    EDIT: I just checked out case 751496 but there's no project attached and it seems to describe capsules etc. The description just tells me you have a problem, it doesn't help at all.
     
  17. skinnysimmons

    skinnysimmons

    Joined:
    Oct 6, 2012
    Posts:
    20
    K.
    751578 uses 3D collisions, and the other game (image above with the fish) uses 2D circle colliders. However it seemed the resulting collision accuracy was similar. My apologies for grouping the two together. So, technically, I'm having issues with both 2D and 3D.
     
  18. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    The two use completely different systems, one PhysX and the other Box2D so no idea why you're getting the same problem on both.

    Again, I need a simple, stripped-down project that reproduces the problem.
     
  19. TimB

    TimB

    Joined:
    Jan 19, 2011
    Posts:
    65
    I worked with @skinnysimmons on the initial screenshot he sent (fish and bubble). I tried to recreate a bare scene with 3 circles that mimic the behavior that was used in that game. I was about to post it, then I saw Unity 5.3 just came out so I upgraded to that and I'm still getting the same overlapping.

    It may have something to do with the speed of the object and how we are moving the object with Vector2.MoveTowards on a kinematic rigidbody. Though at the speed we are moving I wouldn't think we would get that much overlap even using discrete detection and as skinnysimmons said, this setup worked great on Unity 4.x back in Feb.

    It was a fairly large upgrade to 5.2.3, so it would not surprise me at all if there is some setting that was added that we need to adjust to get this working again, but we have done quite a bit of digging into this and haven't had much success.

    If you press play and pause right away you will see similar overlap to the screenshot.
     

    Attached Files:

  20. BugKiller

    BugKiller

    Joined:
    May 8, 2014
    Posts:
    23
    Hello,
    i'm using Version 5.2.3p2 and OnTriggerEnter2D(Collider 2D) is not working with Collider2D, PolygonCollider2D, BoxCollider2D nor CircleCollider2D. I can check the objects are colliding with a simple print to the console on OnTriggerStay2D() but the collision is not triggered when it starts.

    The weird thing is that sometimes it works and others it doesn't. Another important thing is that I didn't change any of the objects' properties or code for more than one year and it stopped working with the last Unity updates.

    This is my code:

    Code (CSharp):
    1.     void OnTriggerEnter2D(Collider2D otherCol)
    2.     {
    3.         var enemy = otherCol.GetComponent<Enemy>();
    4.         if (enemy == null)
    5.         {
    6.             //Debug.Log("enter field no enemy component " + otherCol.gameObject.name);
    7.             return;
    8.         }
    9.  
    10.         enemy.EnteredField();
    11.     }
     
  21. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    Okay so now that I've got a project, I can see what you're doing.

    The problem here is that you're causing the overlap yourself by moving the kinematic body into a position where the attached circle collider is overlapping another. The body isn't moving i.e. it doesn't have any linear velocity; you're just 'transporting' it instantly from one position to another. The physics system won't solve an overlap instantly, it may take a few physics updates to solve large overlaps as the ones you're causing but again, you're constantly moving into the object that the physics system is trying to resolve overlaps for. To make matters worse, it's being done in the 'Update' which is moving it per-frame!

    When you reposition an object, continuous collision-detection isn't used because the object isn't moving through space as it has zero velocity and to the physics system, it isn't moving.

    Instead of manipulating the Transform, use the following methods:

    Rigidbody2D.MovePosition
    Rigidbody2D.MoveRotation

    These move a dynamic or kinematic body from its current position to the target position but causes it to move through the intervening space resulting in accurate collisions that also work with continuous collision detection mode like so:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class GreenMovement : MonoBehaviour
    4. {
    5.     private float m_Speed = 0.1f;
    6.     private Vector2 m_Position;
    7.     private Rigidbody2D m_Body;
    8.  
    9.     void Start ()
    10.     {
    11.         m_Body = GetComponent<Rigidbody2D> ();
    12.         m_Position = transform.position;
    13.     }
    14.  
    15.     void FixedUpdate()
    16.     {
    17.         m_Position.y -= m_Speed;
    18.         m_Body.MovePosition (m_Position);
    19.     }
    20. }
    This works perfectly and causes the circles to collide accurately.
     
  22. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    Please don't hijack threads like this. Post in another thread please.

    EDIT: I believe this issue is where there's a single physics-update delay, is already fixed and should be in a future patch release for both 5.2 & 5.3.
     
    Last edited: Dec 9, 2015
  23. BugKiller

    BugKiller

    Joined:
    May 8, 2014
    Posts:
    23
    Sorry but I think you are being rude with answers like "Please don't hijack threads like this." and "Let's stop the 'me too' until we get some real information otherwise these threads become confusing."

    As you asked I provided more information about the problem instead of just saying me too... I thought you would prefer to have all the related issues inside the same thread to gather all the useful information from you users in just one thread instead of all of us spamming new threads with the same bug. But... if you prefer so, I created a new thread for this issue.

    Regards.
     
  24. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    I am not being rude; simple jumping in with another issue makes threads like this difficult to communicate with each other. I was also polite when I said please. The fact that you don't like what I asked doesn't mean I'm being rude.

    So many threads have this problem and 99% of the time I ignore it. You are assuming that your problem has something to do with the issue being discussed here. Let's keep it separate for now.
     
  25. Shadeless

    Shadeless

    Joined:
    Jul 22, 2013
    Posts:
    136
    @MelvMay Hey, I also want to say that my Physics2D.OverlapArea checks which were working in 5.2.2 started malfunctioning in 5.3. I'm also doing stuff in Update and using my own custom Character Controller and I basically used Physics2D as utility methods to check bounding boxes and to do raycasting, and since they worked in the previous version I think you guys must have messed something/somewhere up. Some of the changes you've made must have influenced this.

    I'd really like to know why these things are happening right now.

    Regards
     
  26. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    You provide no information whatsoever for me to help you so please post a bug report or provide more information. Also, this has nothing whatsoever to do with the thread topic and should be posted separately.

    Have you tried 5.2.3p2? You might find your problem didn't start in 5.3.
     
  27. skinnysimmons

    skinnysimmons

    Joined:
    Oct 6, 2012
    Posts:
    20
    Thank you for all your help @MelvMay
     
  28. TimB

    TimB

    Joined:
    Jan 19, 2011
    Posts:
    65
    @MelvMay it looks like your solution will solve our problem. Not sure how I missed it, but I was not even aware of the Rigidbody2D.MovePosition method. I think we were just lucky that it was working so well before. Thanks!
     
  29. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    You're welcome but it is still a bug that will be fixed; we certainly didn't intend to change the behaviour. Glad you're working again though.