Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

2D Character Controller tutorial leads to stuck on a corner

Discussion in '2D' started by bluefoxicy, Jan 7, 2015.

  1. bluefoxicy

    bluefoxicy

    Joined:
    Jan 2, 2015
    Posts:
    15
    This leads to a problem where jumping at a box collider and landing on the top corner gets you stuck. Can't walk toward the platform, and won't fall; you only fall if moving away.

    I'm using some semi-complex movement code:

    Code (CSharp):
    1.     public float maxSpeed = 10f;
    2.  
    3.     void HandleInput() {
    4.         // Walking left/right
    5.         float move = Input.GetAxis ("Horizontal");
    6.         float forceMultiplier = 0.1f;
    7.  
    8.         if (Mathf.Abs (rigidbody2D.velocity.x) < maxSpeed) {
    9.             forceMultiplier = 5 * (1 - Mathf.Abs (rigidbody2D.velocity.x) / maxSpeed);
    10.             if (!onGround)
    11.                 forceMultiplier *= 0.2f;
    12.         }
    13.         rigidbody2D.AddForce (new Vector2 (move * maxSpeed * forceMultiplier, 0));
    14.     }
    This allows for reduced air control, rapid acceleration, and force-based movement.
     
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    make 2 colliders for player, one circle2d as"wheel" and other box2d for body. Or make physics materiall 2d for colliders with 0 friction.
     
  3. bluefoxicy

    bluefoxicy

    Joined:
    Jan 2, 2015
    Posts:
    15
    That's exactly what I did. The player is two colliders, as in the tutorial. I linked the 2d controller tutorial so you'd know what I was working with.

    The circle collider gets caught on the edge of a rectangle collider, and sticks. Then I can't move. It winds up a few pixels below the platform surface, so can't move toward the platform; it's just pressing against the side.

    I haven't made the platforms or player zero friction because then they'd slide forever.

    EDIT: It looks like making a bigger circle fixed it.
     
    Last edited: Jan 7, 2015
  4. Manny Calavera

    Manny Calavera

    Joined:
    Oct 19, 2011
    Posts:
    205
    How big is your collider now?

    I have similar issues but haven't found a solution yet. Tried different setups, different scales but no luck. Even opened a bug that was resolved 'by design'.