Hi, I’ve googled pretty hard for anyone with my problem, but to no avail. So here goes:
My raycast collides on seemingly nothing. Raycasthit.distance returns “42.62…” and Raycasthit.collider returns “null”.
{
RaycastHit hit;
Physics.Raycast(transform.position, direction, out hit);
Debug.DrawRay(transform.position, direction * hit.distance, Color.green, 4f, true);
}
I’ve also tried increasing the raycast distance “manually” (even though that wouldn’t make sense), with
Physics.Raycast(transform.position, direction, out hit, mathf.infinity);
So yeah, what is going on?
Thanks for your time!
EDIT:
It seems like I provided too little code. I’ve figured out that it apparently is relevant to mention that the raycast is made inside of a for loop:
for(int i =0; i < x; i++)
{
for (int j = 0; j < y; j++)
{
RaycastHit hit;
Physics.Raycast(transform.position, direction[i,j], out hit);
}
}
hit.distance works properly (i.e. is able to become infinitely large) as long as hit.distance never has been smaller earlier in the loop.
Example: Physics.Raycast(transform.position, direction[0,0], out hit) is always able to return infinty, whereas
Physics.Raycast(transform.position, direction[x-1,y-1], out hit) almost never is (since the raycast is bound to hit something until then).