Problem with simple jumping.

Hello, I’ve been stuck on this problem so much and I can’t find a solution. So I have a ball that moves around completely fine but jumping isn’t working it supposed to. It jumps fine EXCEPT on FLAT surface. I find this very odd ( I’m losing my mind can’t find a way to make it work). I’ve put up some images for you to see. images

This is my whole player script.

public class BasicMovement : MonoBehaviour {

public float speed;
public float desiredMaxSpeed;
public float jumpHeight;
public float airHover;

private Rigidbody rb;
private bool grounded;
private bool isjumping;
private bool isMoving;


void Start()
{
    rb = GetComponent<Rigidbody>();
}



void OnCollisionStay(Collision col)
{
    if (col.gameObject.tag == "Walls")
        grounded = false;
    else
    grounded = true;
    isMoving = true;

}

void OnCollisionExit(Collision col)
{
    grounded = false;
    isMoving = false;
}


void Update()
{
    if(Input.GetButton("Jump") && grounded == true)
    {
        isjumping = true;
    }
}

void FixedUpdate()
{
    if (isMoving == true)
    {
        Movement(speed);
        manipulateSpeed(desiredMaxSpeed);  
    }
        Movement(airHover);//ball moves a bit while in air.
    if (isjumping == true)
    {
        BallJumping();
    }
}
void manipulateSpeed(float maxSpeed) //this change the maxSpeed of the ball.
{
    if (rb.velocity.magnitude > maxSpeed)
    {
        rb.velocity = rb.velocity.normalized * maxSpeed;
    }      
}

public void Movement(float currentSpeed)
{
    float moveHorizontal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");

    Vector3 movement = new Vector3(moveHorizontal ,0, moveVertical  )*currentSpeed;
    rb.AddForce(movement * currentSpeed * Time.deltaTime);  
}
void BallJumping()  
{
    rb.velocity = rb.velocity+Vector3.up * jumpHeight;
    isjumping = false;
}

}Note: I increase my gravity to fall faster.

Can someone test this. I don’t know why this is happening.

Your problem is probably the OnCollisionStay(). First of all be sure that ground is not tagged as “walls”. Also mind that if player comes in contact with walls while he is suppose to be grounded, his state will change to “not grounded” because OnCollisionStay() is triggered(it triggers after OnCollisionEnter() which is almost immediately). Then your player will need to get separated from the ground and then contact it again so grounded variable is reset to true.

I would suggest to change the method you use for detection and go for Physics.Raycast() which is much more commonly used. This because a lot of issues can be avoided, many of which cannot be noticed or said. Just Raycast() a line to -Vector3.up and check if it collides with the ground.

-Hope i helped