Ground check problem

So I started a game on my own and actually it’s working pretty good, except for a little issue.
I use a sphere for my character and he have to jump. But when the sphere is on a different platform
besides the floor. The ground check is checked out contstantly.

I bet it has something to do with the script ’ cause I’m a noob at code writing.

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour
{
    public bool grounded = true;
    public float jumpPower = 1;
    public float speed;

    private Rigidbody rb;

    // Use this for initialization
    void Start ()
    {
        rb = GetComponent<Rigidbody> ();
    }
   
    // Update is called once per frame
    void Update ()
    {
        float moveHorizontal = Input.GetAxis ("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");


        Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
        if(!grounded && GetComponent<Rigidbody>().velocity.y == 0)
        {
            grounded = true;
        }
        if (Input.GetKey(KeyCode.Space) && grounded == true)
        {
            this.GetComponent<Rigidbody>().AddForce(new Vector3(0,jumpPower,0));
            grounded = false;
        }

        rb.AddForce (movement * speed);
    }
}

thanks for your help.

You could try using a raycast to see if the ground is below the player.
A raycast is like a line out from a point, and if it collides with something, you can find out what it is.

In this case, it checks to see if there is anything under the player, if there is, it can jump.

You can also get informaton back from the RaycastHit like the name of surface, so you could have different jump values, or none at all say if the surface was water or something.

Rigidbody rigidbody;

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

void Update ()
{

RaycastHit hit;

if (Input.GetKeyDown (KeyCode.Space)) {

//-transform.up is the down direction of the player's direction, the hyphen grabs the inverse
if (Physics.Raycast (transform.position, -transform.up, out hit, .6f)) {

print("Grounded");
print("Player is above " + hit.collider.gameObject.name);

rigidbody.velocity = newVector3 (0, 8, 0);

}

}

}

EDIT: Also, you don’t need to use GetComponent everytime you want to access it. You already did so in your start function, so you can just call rb.TheFunctionYouWant each time instead.

thanks, working fine.