I have a character in Unity that I'm using a raycast to have him jump. But even when the raycast doesn't hit the ground (I can see the ray with the debug output) the player still can jump. Any ideas why the ray is always thinks it is colliding? Could the ray be hitting my character collider, causing it to be true? Ive been search online for hours and nothing I find is fixing the situation. Here is my code:
void FixedUpdate()
{
Ray ray = new Ray();
RaycastHit hit;
ray.origin = transform.position;
ray.direction = Vector3.down;
bool output = Physics.Raycast(ray, out hit);
Debug.DrawRay(ray.origin, ray.direction, Color.red);
if (Input.GetKey(KeyCode.Space) && output)
{
r.AddForce(Vector3.up * 1f, ForceMode.VelocityChange);
}
}
ray.origin
to be outside of your character collider? – Kolichikov