Weird issue I’m having :
I’m firing a 1 meter large boxcast DOWN towards the ground. It starts 1 meter off the ground and can at a maximum go down 1 meter. (so, it should have a hit distance of 1).
The issue is that the boxcast says the hit distance is .9975, not 1.
A raycast starting at the bottom of the box going the same maximum distance of 1 meter registers a hit distance of 1.
That makes make me think that the boxcast is starting .0025 meters too low, but the hit.point.y value always equates the raycast even when the distance differs.
In this example, the box/raycast is only .701 meters off the ground. The hit.point.y of both is equal, but the hit.distance differs. Any idea what is going on? Is it just an oversight by me? Thanks
Boxcast is RED ▉
Raycast is GREEN |
void collision()
{
RaycastHit boxhit, rayhit;
Physics.Raycast(new Vector3(0f, 1f, 0f), Vector3.down, out rayhit, 1f);
Physics.BoxCast(new Vector3(0f, 1.5f, 0f), new Vector3(.5f, .5f, .5f), Vector3.down, out boxhit, Quaternion.identity, 1f);
Debug.DrawRay(new Vector3(boxhit.point.x, 1f, boxhit.point.z), Vector3.down*boxhit.distance, Color.red);
Debug.DrawRay(new Vector3(0f, 1f, 0f), Vector3.down*rayhit.distance, Color.green);
Debug.Log("boxhit.point.y: " + boxhit.point.y + " boxhit.distance: " + boxhit.distance);
Debug.Log("rayhit.point.y: " + rayhit.point.y + " rayhit.distance: " + rayhit.distance);
}
UPDATE:
I even put in the Physics.Boxcast demo script (which was broken at first, using full size instead of halfExtents). And placing a boxes faces 1 meter apart from each other gives a hit distance of .9975. Is this a bug? So confused.
void FixedUpdate()
{
//Test to see if there is a hit using a BoxCast
//Calculate using the center of the GameObject's Collider(could also just use the GameObject's position), half the GameObject's size, the direction, the GameObject's rotation, and the maximum distance as variables.
//Also fetch the hit data
m_HitDetect = Physics.BoxCast(m_Collider.bounds.center, transform.localScale *1/2, transform.forward, out m_Hit, transform.rotation, 1f);
if (m_HitDetect)
{
//Output the name of the Collider your Box hit
Debug.Log("Hit : " + m_Hit.distance);
}
}