The player doesn't fall when hits a platform

I’m currently making a platformer game and I have an issue with Physics. When I jump on a wall and holding A/D then the player doesn’t fall until I stop holding A/D. All platforms in my game have ground layer, rigidbody and tilemap collider (because I’m working with tilemaps).

Here is my code:

    [SerializeField] private float speed;
    [SerializeField] private float jumpForce;
    [SerializeField] private LayerMask groundLayer;

    private bool canJump;
    private Vector3 inputVector;
    private Rigidbody2D rb;

    private void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    private void Update()
    {
        Movement();
        Jump();
    }

    private void Movement()
    {
        rb.velocity = new Vector2(Input.GetAxis("Horizontal") * speed, rb.velocity.y);
    }

    private void Jump()
    {
        CheckGround();

        if (Input.GetKeyDown(KeyCode.Space) && canJump)
        {
            rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
        }
    }

    private void CheckGround()
    {
        float boxDist = 1f;
        float boxAngle = 0f;
        canJump = Physics2D.BoxCast(transform.position, Vector2.one, boxAngle, 
                                    Vector2.down, boxDist, groundLayer);
    }

I’ll take a guess that it is friction: you’re pushing yourself against the wall and sticking.

Try putting some super-slippery PhysicMaterial2Ds on you and the thing you’re hitting.

Thanks. I thought that It was problem in my code, but it turned out to be just set friction to “0” in physics material of player

1 Like