Problems with friction ( Physic2D ) in Unity3D

Viewed 51

Describe the problem: So my player is stuck to the wall when he jumps and moves to the right side at the same time. Watch the video below to imagine it better.
Watch the video for better illustration: HERE

If there is anything to do with code, here is the PlayerMovement script:

public class PlayerMovement : MonoBehaviour
{
    Vector2 vector2Move;
    Rigidbody2D rb2D;
    [SerializeField] float playerSpeed;
    bool isGrounded;
    Collider2D playerCollider;
    float theCurrentGravityScale;
    private void Awake()
    {
        rb2D = GetComponent<Rigidbody2D>();
        playerCollider = GetComponent<Collider2D>();
    }
    void Start()
    {
        theCurrentGravityScale = rb2D.gravityScale;  
        
    }
    void Update()
    {
        Run();
    }
    void OnJump(InputValue value)
    {
        if (playerCollider.IsTouchingLayers(LayerMask.GetMask("Ground")) && value.isPressed)
        {
            rb2D.velocity += new Vector2(0f, jumpForce);
            animatorPlayer.SetBool("isIdling", false);
        }  
    }
    void OnMove(InputValue value)
    {
            vector2Move = value.Get<Vector2>();
    }

    void Run()
    {
            animatorPlayer.SetBool("isRunning", true);

            Vector2 playerMovement = new Vector2(vector2Move.x * playerSpeed, rb2D.velocity.y);
            rb2D.velocity = playerMovement;
    }
    private void OnCollisionEnter2D(Collision2D collision)
    {
        animatorPlayer.SetBool("isGrounded", true);  
    }
1 Answers

It seems to me like the player collider is getting stuck with the tilemap collider, you can create a new physics material 2D (Assets > Create > 2D > Physics Material 2D) and set the friction to 0

Then you need to assign the material to the Rigid Body of the player, how many colliders do you have on the player?

Related