Raycast not changing value
I have a raycast to detect when the player is on the ground, however it doesn't seem to want to flip the bool when the player is on the ground (so the player can jump). I had a different way I was doing this before with the OnCollision functions, but I couldn't get the Player Attack script to see the value so I thought I'd give this a try.
The code enters into the if block and outputs the debug line, but it doesn't seem to want to trigger the boolean to switch. Maybe it's not working exactly how I think it should
#region Detect Ground
void DetectGround()
{
distance = 0.2f;
direction = new Vector3(0, -1, 0);
//Draw Ray
Debug.DrawRay(transform.position, direction * distance, Color.green);
//Check for collision
if (Physics.Raycast(transform.position, direction, out groundHit, distance) &&
this.groundHit.collider.gameObject.CompareTag("Floor"))
{
Debug.Log("Hit the floor");
onFloor = true;
playerAttack.testJump = true;
}
else
{
onFloor = false;
playerAttack.testJump = false;
}
}
#endregion
Comment