My Bool function is returning False but it should be true in my opinion. Csharp C#
I am trying to get a cute little cube to slide around and just mind it's own buisness but every once in a while when it hits a wall it just stops due to my bool function is returning false. the bool function is a bunch of raycasts which goes from the cube and down in the floor. when any of these raycasts hits the floor the function should return true, else false. here's the the code!
public bool isGround()
{
bool frontRight = Physics.Raycast (transform.TransformPoint(new Vector3(0.51f,-0.45f,0.51f)), -transform.up, 0.05f);
bool frontLeft = Physics.Raycast (transform.TransformPoint(new Vector3(-0.51f,-0.45f,0.51f)), -transform.up, 0.05f);
bool backLeft = Physics.Raycast (transform.TransformPoint(new Vector3(-0.51f,-0.45f,-0.51f)), -transform.up, 0.05f);
bool backRight = Physics.Raycast (transform.TransformPoint(new Vector3(0.51f,-0.45f,-0.51f)), -transform.up, 0.05f);
bool bottom = Physics.Raycast (transform.TransformPoint(new Vector3(0,-0.45f,0)), -transform.up, 0.04f);
Debug.DrawRay (transform.TransformPoint(new Vector3(0.5f,-0.45f,0.5f)), -transform.up * 0.1f, Color.blue);
Debug.DrawRay (transform.TransformPoint(new Vector3(-0.5f,-0.45f,0.5f)), -transform.up * 0.1f, Color.blue);
Debug.DrawRay (transform.TransformPoint(new Vector3(-0.5f,-0.45f,-0.5f)), -transform.up * 0.1f, Color.blue);
Debug.DrawRay (transform.TransformPoint(new Vector3(0.5f,-0.45f,-0.5f)), -transform.up * 0.05f, Color.blue);
if (frontRight || frontLeft || backLeft || backRight||bottom) {
return true;
} else {
return false;
}
}
Comment