Problem with raycasting, checking for ground doesn't work

I have troubles with checking for ground in my 2.5D platformer. Here’s script I use for player’s movement

using UnityEngine;
using System.Collections;

public class playerMovement : MonoBehaviour {
	public float movementForce = 0.1f;
	public float jumpForce = 1f;
	public bool ground = false;
	// Update is called once per frame
	void Update () {
		//defining ray
		Ray bottom = new Ray(this.transform.position,Vector3.down);
		//defining RaycastHit
		RaycastHit hit = new RaycastHit();
		//testing for collision, should work, but it doesn't, even if ray is halfway through object
		//this returns false no matter what I try
		bool hitground = this.collider.Raycast(bottom,out hit,20);
		if (hitground){
			//if it collided, test if it is in right distance
			ground = hit.distance<=0.6;}
		//drawing ray
		//logging distance and if it hit (always gives Hit distance: 0 Did hit: false)
		Debug.Log("Hit distance: "+hit.distance.ToString()+" Did hit: "+hitground.ToString());
		//movement, this works fine
		if (Input.GetAxisRaw("Horizontal")==-1){this.rigidbody.AddForce(-movementForce,0,0);}
		if (Input.GetAxisRaw("Horizontal")==1){this.rigidbody.AddForce(movementForce,0,0);}
		//jumping, this doesn't due to stupid raycasting bug.
		if ((ground)&&(Input.GetButtonDown("Jump"))){this.rigidbody.AddForce(0,jumpForce,0);}

Another thing is that I’m using rigid body for movement and spherical collision shape (player character is and will be cube as this is minimalistic game), so player can climb on smaller platforms.
Theoretically it should work as ray is shown passing directly through platform (another cuboid, I’m talking about ray drawn by Debug.DrawRay), but it doesn’t.

Collider.Raycast() only checks for a collision between this specified collider, so you are only raycasting against the collider attached to the player game object. You want to use Physics.Raycast() instead.

Side note: you don’t need to create a new RaycastHit() as you do on line 13…just declare the variable.

Hi! there,

If you read the documentation, you will realise, that calling this.collider.Raycast does a ray-mesh intersection test, only with that collision mesh.
What you want to do is call Physics.Raycast instead, which does a ray-mesh intersection test with every collider in the scene.

Hope this helps,

I´m having the same problem but I´m actually using Physics.Raycast(), my character is standing on the ground but my function doesn´t detect the ground. If I zoom in the collision between my character collider (a box collider) and my platform collider (also a box collider) they look like if they where intersecting a little. I believe this could be the problem but I´m not sure, because if I place anothe platform right below the other one and make the raycast a bit longer then it works. If this is the problem how can I make my colliders not to intersect? if is not the problem then what could it be.