#Unity 6 Rigidbody ground check

1 messages · Page 1 of 1 (latest)

flat ocean
#

Getting back into the swing of things. Before i go a net area of raycast to ground check. Has anyone come up with a better ground check. looking for a way that doesnt need layermask.

flat ocean
#

getting 9.46 ms return from that. wanting something abit faster. my current call is 5.629ms

surreal cliff
#

Well, more specifically as the page details you should use GetContacts

flat ocean
surreal cliff
flat ocean
#

private bool IsGrounded()
{
Ray ray = new(this.transform.position + Vector3.up * 0.25f, Vector3.down);
Debug.DrawRay(this.transform.position + Vector3.up * 0.25f, Vector3.down, Color.red);
if (Physics.SphereCast(ray, 0.3f)) // THIS ISNT WORKING BUT IT WONT IN CURRENT FORMAT JUST COPIED FROM CURRENT UNFISHED SCRIPT
return true;
else return false;

}

flat ocean
#

decided to just go

 {
     float sphereCastRadius = capsuleCollider.radius * _groundCheckRadiusMultiplier;
     Physics.SphereCast(rb.position, sphereCastRadius, Vector3.down, out _groundCheckHit);
     playerCenterToGroundDisatnce = _groundCheckHit.distance + sphereCastRadius;
     return ((playerCenterToGroundDisatnce >= capsuleCollider.bounds.extents.y - _groundCheckDistanceTolerance) &&
             (playerCenterToGroundDisatnce <= capsuleCollider.bounds.extents.y + _groundCheckDistanceTolerance));



 }