I'm learning Unity and want to use Boxcasting to detected if the player is grounded. I have this code:
void Jump()
{
float maxDistance = 0.1f;
RaycastHit hit;
bool isGrounded = Physics.BoxCast(transform.position, transform.lossyScale / 2, Vector3.down, out hit, transform.rotation, maxDistance, groundMask);
if (isGrounded)
rb.AddForce(Vector3.up * jumpForce);
Debug.Log(isGrounded);
}
But it always return false. If I have it inside a OnDrawGizoms method, it works as indented, but if I have it in my Jump() method (as the code above) will it always return false.
I would appreciate any help I could get.