Objects get not detected by Raycast

Hi

I’m using C# and I’m drawing a raycast form an object to another to check if there is a collider between. The problem the raycast doesn’t detects does colliders.

RaycastHit hit = new RaycastHit();
Ray ray = new Ray(transform.position, obj.transform.position - transform.position);
				
if(!collider.Raycast(ray, out hit, detectionRange))
        good1.Add(obj);

Any help would be great.
Thanks.

realm_1

Try Phyics.Linecast for your use case.

Actually, you are checking if there is NOT a collission. That is probably what is wrong.

Thanks for the answer.
It doesn’t work 100 % correct but it’s correct that there is no collision. I want to check if there is NO object between. And I’m working with colliders, so the “obj” is a collider as the other objects.

well if they are intesecting then it’s possible that raycast will not work because if the ray originates inside of a collider then that collider will not be hit. However that is not the case with Linecast.

Ok, thanks I think the first part of my script should work, but the second… Anyways I have to take a closer look may I can solve the problem with Linecast. Otherwise I will post the problems.

Thanks.