Should I use Linecast?

I recently found a post where it mentioned using a Linecast (honestly, I’ve never heard of it until that moment) for a basic third person camera collision-detection. It seems there’s no much information about it in the documentation, and also, there are not so many tutorials. So that leads me to a question: Should really I use it?

It seems useful for very specific situations, but maybe there are better approaches. Also, is there any more info about it out there? I couldn’t find almost anything about the Linecast…

I don’t know if this is the right place to post this, I believe it doesn’t fit on General Discussion, since this is more a question of support. So…I think this is an option.

Physics.Linecast is very similar to Physics.Raycast. The main difference is that Raycast ignores the colliders overlapping the origin point.

For example, if you throw a Raycast from the center of a sphere collider to a point in the outside, it will return True if there’s any other collider in the path of the ray. But if you do the same with Linecast then it will always detect the sphere collider.

So basically Linecast detects every collider including the object from where it’s casting? Is there any practical example where this is correctly applied?

It detects the first collider it touches, including the object from where it’s casting. If you want to detect all colliders at once you should use RaycastAll.

The application cases depend on the specific needs of each project. For example, I wouldn’t use Linecast for third-party camera collision detection because I’ll likely throw the raycast from the character, and I don’t want the character’s colliders to be detected. In this case Raycast or RaycastAll (where you ignore the character’s collider) are good choices.