Player floating when jumping at a wall

I made a small playermovement for a 2d game and its fine till i jump at a wall and it just floats there till i stop moving,i tried making the movespeed 0 when colliding but the problem is that the wall itself has a platform above it(standing on a wall) and i want the player to move normally even when hitting a wall but the gravity affect him.so how can i fix it?
(i don’t the movements to be Axis Horizontal but arrows so don’t care about it)

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public float movespeed = 5f;
    public float jumpforce = 12.5f;
    private Rigidbody2D rb;
    private bool IsGrounded1;



    public Transform groundCheck;
    public float groundCheckRadius = 0.2f;
    public LayerMask groundLayer;
    void Start()
    {
        rb = gameObject.GetComponent<Rigidbody2D>();
    }
    void Update()
    {
        CheckGrounded();
        move();
        jump();
    }
    void CheckGrounded() {
        IsGrounded1 = 
        Physics2D.OverlapCircle(groundCheck.position,
        groundCheckRadius,
        groundLayer);
    }
    void move(){
        float moveInput = 0f;
        if (Input.GetKey(KeyCode.RightArrow)) {
            moveInput = 1f;
        }
        if (Input.GetKey(KeyCode.LeftArrow)) {
            moveInput = -1f;
        }
        rb.velocity = new Vector2(moveInput * movespeed, rb.velocity.y);
    }
    void jump(){
        if (IsGrounded1 && (Input.GetKeyDown(KeyCode.UpArrow))) {
            rb.velocity = new Vector2(rb.velocity.x, jumpforce);
        }
    }
    private void OnDrawGizmos() {
        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(groundCheck.position,groundCheckRadius);
    }
}

Paste your code using code tags, don’t take a picture with your phone. It’s very hard to read.

Yea sorry,It’s just because the internet cable was cut.i will write it.

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public float movespeed = 5f;
    public float jumpforce = 12.5f;
    private Rigidbody2D rb;
    private bool IsGrounded1;



    public Transform groundCheck;
    public float groundCheckRadius = 0.2f;
    public LayerMask groundLayer;
    void Start()
    {
        rb = gameObject.GetComponent<Rigidbody2D>();
    }
    void Update()
    {
        CheckGrounded();
        move();
        jump();
    }
    void CheckGrounded() {
        IsGrounded1 = 
        Physics2D.OverlapCircle(groundCheck.position,
        groundCheckRadius,
        groundLayer);
    }
    void move(){
        float moveInput = 0f;
        if (Input.GetKey(KeyCode.RightArrow)) {
            moveInput = 1f;
        }
        if (Input.GetKey(KeyCode.LeftArrow)) {
            moveInput = -1f;
        }
        rb.velocity = new Vector2(moveInput * movespeed, rb.velocity.y);
    }
    void jump(){
        if (IsGrounded1 && (Input.GetKeyDown(KeyCode.UpArrow))) {
            rb.velocity = new Vector2(rb.velocity.x, jumpforce);
        }
    }
    private void OnDrawGizmos() {
        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(groundCheck.position,groundCheckRadius);
    }
}

Right, so this is a common problem with input. If you force the body into the wall, you’ll get maximum friction.

One thing you could try is to add a physics material to your rigidbody that has no friction. If that fixes the problem you’re facing, you could apply that material while in the air. That’s the most straightforwards, least intrusive thing I can think of.

1 Like

Thanks, it actully worked