2D Character incorrectly bounces on BoxCollider2Ds

I have a basic prototype for v2 of my game and I have added a RigidBody2D to my character object. I’ve added a BoxCollider2D and I have BoxCollider2Ds on my platforms. I’m setting the velocity of the player in FixedUpdate and sometimes she gets stuck on a platform. Seems to be random. I have to jump to get over it. To combat this, I’ve added a CircleCollider2D to my players feet. A tactic I’ve seen used a fair bit. This prevents her from getting stuck but it causes her to bounce up off the “snagging” collider. It’s almost as if there is a slight gap randomly (there isn’t, the platforms are instantiated at runtime)

Here’s a clip of what’s happening. Note that I have simply attached the camera as a child of the player for now.

http://www.nfnproductions.com/Videos/CraneJumper2-bounce.mp4

Here is my script attached to my player:

namespace NfnProductions.CraneJumper.Unity.Assets.Scripts {

    using UnityEngine;

    public class Player : MonoBehaviour {

        private Rigidbody2D _rigidbody;

        public float MaxSpeed = 10f;
        public float CurSpeed = 0f;
        public float SpeedIncrementor = 0.1f;
        public float JumpForce = 700f;

        public bool IsGrounded = false;
        public Transform GroundCheck;
        public float GroundRadius = 0.2f;
        public LayerMask WhatIsGround;

        private void Start() {
            _rigidbody = GetComponent<Rigidbody2D>();
        }

        private void FixedUpdate() {
            IsGrounded = Physics2D.OverlapCircle(GroundCheck.position, GroundRadius, WhatIsGround);
            Debug.Log("Grounded: " + IsGrounded.ToString());
            if (Input.GetKey("x")) {

                Debug.Log("Sprint Pressed");
                this.CurSpeed += SpeedIncrementor;
                if (CurSpeed > MaxSpeed) CurSpeed = MaxSpeed;

                _rigidbody.velocity = new Vector2(this.CurSpeed, _rigidbody.velocity.y);
            }
            else {
                this.CurSpeed = _rigidbody.velocity.x;
            }
        }

        private void Update() {
            if (this.IsGrounded && Input.GetKeyDown(KeyCode.Space)) {
                _rigidbody.AddForce(new Vector2(0, JumpForce));
            }
        }
    }
}

I’m using velocity but I have tried using AddForce. I have removed the BoxCollider2D from the player (so I only have a CircleCollider2D. I have played around with Gravity and GravityScale on the RigidBody2D (My overall Gravity is set to -30). I’ve checked there are no gaps in the colliders, I’ve reduced the number of platforms in case it’s a performance issue.

I’m all out of ideas. I’m sure it’s something simple, this is just a basic function so I must have done something wrong.

Thanks

UPDATE - 2016-04-03:

I’ve found that it is to do with the platform colliders. I have instantiated just one platform but with an X scale of 250 meaning I have 1 giant horizontal platform. The movement is smooth as I would expect.

I have tried using Edge colliders, still same.

This seems like real basic functionality and I’m in a new project so I must have something fundamentally wrong or others must surely be facing this problem! I can’t find anything on the latter so it must be something I have done!

Update 2 - 2016-04-03:

I have recreated it in a new Unity project (Unity 5.3.3.f1) and uploaded it here if anyone would like a look. When it’s running, hold “x” on your keyboard to add velocity to the player. She will bounce along sometimes (you may have to look carefully)

Demo Project

Steps I did.

  1. New Unity 2d Project
  2. Added Crane Part as a prefab, added box collider 2d
  3. Add player, gave rigidbody2d, set constraints z to fixed. Added circle collider 2d to her feet.
  4. Added the script to add velocity to the player

You can try to change EDIT/PROJECT SETTINGS/TIME to solve the stuck problem. When you reduce the time the fixedUpdate methode is called more often and the physiks too.
The second thing you can do is to check the offset and the size of your collieders.

Whilst this isn’t the answer I was originally looking for, I have found a workaround and it is probably more efficient than my original idea.

Instead of including a BoxCollider2D on my prefab for my crane-platform, I am instead Instantiating all of my crane-platforms (which are just sprites now) and then by calculation, drawing a BoxCollider2D around each group of crane-platforms. The platforms need to be instantiated on level start so I am just adding a BoxCollider2D after this.

I think this will be more efficient as there will only be 3-4 larger colliders on screen as opposed to 20-30 smaller ones.

She now runs smooth and is consistent.

Thanks for your help everyone.