i’m trying to add collision to my character in 3D, and for some reason my boxcast is not returning true even though I have the ground layer set to “ground”, and whatisGround is set to the proper ground layer mask.
Here’s my script
public class PlayerMovement : MonoBehaviour {
public Collider m_Collider;
public RaycastHit m_Hit;
public void Awake ( ) {
m_Collider = GetComponent <Collider> ( );
}
public bool IsGrounded ( ) {
// Fetch the center of the Collider volume
m_Center = m_Collider.bounds.center;
// Fetch the size of the Collider volume
m_Size = m_Collider.bounds.size;
m_SizeY = ( ( m_Size.y / 2.0f ) + 0.01f );
m_Min = m_Collider.bounds.min;
m_Max = m_Collider.bounds.max;
var colliderExtentsY = m_Collider.bounds.extents.y;
var rayPosition = ( m_Center );
var rayDirection = ( -transform.up * m_SizeY );
isGrounded = Physics.BoxCast (
rayPosition, m_Size,
rayDirection, out m_Hit,
transform.rotation, m_MaxDistance,
whatIsGround
);
return isGrounded;
}
public void Update ( ) {
Debug.Log (
$"IsGrounded ( ) : { IsGrounded ( ) }"
);
}
}
Any help is absolutely appreciated!