Check if is Grounded - Raycast

Hi guys,

I’m trying to make the character jump.

But he can only jump when is on the ground.

The check a I made it’s always saying that he not on the ground.

i’m trying the code below.

Some ideia of why this “check” is not working?


public class playerControl : MonoBehaviour {

	public GameObject player;
	public float speed;

	//Limits var
	public float minH;
	public float minX;
	public float maxX;

	//Jump var
	public float jumpH;
	public bool isGrounded = false;

	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {
		//Horizontal Move
		float translation = Input.GetAxis ("Horizontal") * speed;
		player.transform.Translate (translation, 0, 0);

		if (Input.GetButtonDown ("Jump") && isGrounded) {

	//Scene Limits
		if (player.transform.position.y < minH) {
			player.transform.position = new Vector2 (player.transform.position.x, minH);
		if (player.transform.position.x < minX) {
			player.transform.position = new Vector2 (minX, player.transform.position.y);
		if (player.transform.position.x > maxX) {
			player.transform.position = new Vector2 (maxX, player.transform.position.y);

	//Check and Jump
	void Jump () {
		if (!isGrounded) {
		isGrounded = false;
		rigidbody.AddForce (new Vector3 (0, jumpH, 0), ForceMode.Force);

	void FixedUpdate (){
		isGrounded = Physics.Raycast(transform.position, Vector3.up, + 1.1f);

Well Guys,

I find a solution

I created a empty object to check if my character is on ground.
Put the object a little below the character sprite, and created a hierarchy in the layers with the name “Ground”

and used the code below to check:
isGrounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer(“Ground”));

I expect don’t have more trouble with this. (But I think I will…)