# Feedback A mistake or something that needs a Fix in unity script reference about ( Physics.BoxCast )

Discussion in 'Documentation' started by Propixel, Aug 13, 2023.

1. ### Propixel

Joined:
May 28, 2017
Posts:
1
Hi, hope you have nice times.
in the script here https://docs.unity3d.com/ScriptReference/Physics.BoxCast.html
code works well but there is something that isn't match.
- - - - - - - - - -
in this line :

m_HitDetect = Physics.BoxCast(m_Collider.bounds.center, transform.localScale, transform.forward, out m_Hit, transform.rotation, m_MaxDistance);

we are defining the size of the box as the scale of the object, since we know it's a vector3 halfExtents and will be double.
and if we are going with this size, then in the void OnDrawGizmos() we need to double the size of cube that we are drawing, in this line :
Gizmos.DrawWireCube(transform.position + transform.forward * m_Hit.distance, transform.localScale);
- - - - - - - - - -
So : we need to match the size of the castbox to the size of the drawing box in the gizmo.
and the best solution is just use *0.5f on the size of the box in the casting function.

m_HitDetect = Physics.BoxCast(m_Collider.bounds.center, transform.localScale*0.5f, transform.forward, out m_Hit, transform.rotation, m_MaxDistance);

- - - - - - - - - -
it's what we get with the current codes in the reference :

and its what we get after fixing the code :

As you can see in the first picture the gizmo box is in the air because the size of the Boxcast is twice bigger, by changing the size of that to 1/2 the problem got solved and we make a cube exactly on the surface of the place we are casting box at.
- - - - - - - - - -
Thank you >.<

Last edited: Aug 13, 2023