Bounds.IntersectRay behavior when origin is inside bounds?
i feel like i must be missing something here...
Bounds bounds = new Bounds(Vector3.zero, Vector3.one);
Ray ray = new Ray(new Vector3(0, 0, 0), new Vector3(0, 0, 1));
float t;
if (bounds.IntersectRay(ray, out t))
{
Debug.Log(t);
}
this code gives t = -0.5, which while correct, isn't what i'd expect. i'd expect it'd prefer the intersection point in the positive direction along the ray. but i gave it the benefit of the doubt and assumed that with two equidistant intersection points maybe it just picks one at random. so i tried biasing along the ray:
Ray ray = new Ray(new Vector3(0, 0, 0.1), new Vector3(0, 0, 1));
but this gives me t = -0.6! to get the point in the direction i want, i found i could invert the ray direction like so:
Ray ray = new Ray(new Vector3(0, 0, 0.1), new Vector3(0, 0, -1));
which gives me t = -0.4.
it's not just me, right? this is pretty strange behavior? maybe even worth reporting as a bug?
Not just you. I just got bitten by this as well. It's counter-intuitive at the very least.
Your answer
Follow this Question
Related Questions
Finding an origin for two rays 0 Answers
bounds.Intersects returning wrong values 0 Answers
How can I get a bounding box for an imported fbx clip? 0 Answers
Editor Scripting: Bounds editor with BoxCollider-like scene controls 2 Answers
How do I flatten part of mesh, based on another object? 0 Answers