Hello Unity Community.
I have a Problem with the new Unity Boxcast.
I’m using a Rigidbody Character with pure Physics movement and a Boxcolider.
I have done Grounddetection with Raycasts, but it doesn’t work on slopes the way i need it to work.
So i decided to replace it with a Physics.Boxcast and it works perfectly on the slopes.
But now i have the problem that the Detection stops working as soon as the Boxcolider sits on a flat surface, without any space between (it detects collision if there is a little space between the box and the flat surface).
This is my BoxCast call:
private void GroundCheck()
{
m_PreviouslyGrounded = m_IsGrounded;
if(Physics.BoxCast( new Vector3(transform.position.x , transform.position.y , transform.position.z ),
new Vector3((m_Box.size.x * 0.9f), m_Box.size.y, (m_Box.size.z * 0.9f)) * 0.5f,
-Vector3.up,
out hitInfo,
m_Box.transform.rotation,
groundCheckDistance
))
{
Debug.DrawRay(hitInfo.point, hitInfo.normal,Color.red,1.0f);
...
works perfect on slopes:
works with little space between collider and ground:
doesn’t work as soon as collider covers the flat ground:
I tryed to change positions and size of the BoxCast, but it only changes the distance between collider and flat survface where the collision is detected.
As soon as the collider covers the ground, no settings seem to cause a collision.
Is there anyone who already used BoxCast for GroundCheck, and can tell me what i’m doing wrong?
I can’t replace the Boxcollider and use common sugested snaping methods or the standart Charactercontroller for various reasons, so i need to execute Groundcheck along the entire bottom face of my Boxcollider and get the normal angle of that collision.
The bad solution i have right now is still performing the normal groundcheck raycast i did before, to cover flat surfaces.
But i would like to do it with a single boxcast, because boxcast should be capeable of doing it.
Edit: As usual i found the Solution directly after creating the Thread.
What i did in the previous code, was setting the BoxCast Height to BoxHeight and BoxCast Distance to a very small number.
You actualy have to do it the other way around. Setting up the Height of the Boxcast to something small and the BoxCast distance to be big enough to reach the outer bounds of your collider (Box height / 2 if you use Box center as origin)


