Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Bug Capsule Collider 2d Acting like box collider. (Also, updated unitychan script for those with issues)

Discussion in '2D Experimental Preview' started by Caliber-Mengsk, Jun 14, 2016.

  1. Caliber-Mengsk

    Caliber-Mengsk

    Joined:
    Mar 24, 2010
    Posts:
    683
    So, I was messing around with this since it's out now. And there are some issues that I've had to combat in the past (I'm the programmer for tilemaster, which these features will be replacing soon). Number one, and the biggest hurdle is that when you have two colliders (polygon or box colliders) right next to each other, the character catches on those tiles. This is pretty sucky as it stops the character in it's tracks. Being a capsule should have fixed this, but it didn't. In fact, though the capsule looks like a capsule, it's actually just a box collider at the moment.

    It's easy enough to tell just by partially walking off an edge.


    Here is a capture of the catching issue cause of this. (this further shows a box collider in action instead of a capsule collider as it's the side of the capsule getting stuck, not the bottom)


    This is quite annoying. Is this intentional? or is this another of many things not fully implemented?

    Lastly, there is quite the bug with the unitychan movement script. It doesn't check for collisions below, it simply looks to see if it's overlapping with the ground. Problem with this is that you can then scale walls with ease. Only takes a smidgeon more effort, but it's pretty much fixed by replacing the fixed update with the following

    (this is mainly for other people that may be having issues since the current method effectively gives you infinite wall and ceiling jumping)

    Code (CSharp):
    1.  
    2.     void OnCollisionStay2D(Collision2D col)
    3.     {
    4.         GroundedCheck(col);
    5.     }
    6.  
    7.     void OnCollisionExit2D(Collision2D col)
    8.     {
    9.         GroundedCheck(col);
    10.     }
    11.  
    12.     void GroundedCheck(Collision2D col)
    13.     {
    14.         m_isGround = false;
    15.         if (m_rigidbody2D.velocity.y <= 0)
    16.         {
    17.             foreach (ContactPoint2D contact in col.contacts)
    18.             {
    19.                 if (contact.point.y <= transform.position.y - m_CapsuleCollider2D.bounds.extents.y)
    20.                 {
    21.                     m_isGround = true;
    22.                 }
    23.             }
    24.         }
    25.         m_animator.SetBool("isGround", m_isGround);
    26.     }
    27.  
     
    Last edited: Jun 14, 2016
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    2,018
    It's a known bug that was reported just after the release. If you look, capsule/capsule contact works as expected but the bug is between capsule/polygon contact.

    This is being fixed.