linecast hits its own origin object

im making a script where two spheres keep moving randomly around until they can see eachother, when they can they move towards each other and then multiply on contact, and then the new ones do the same

my problem is im using a linecast to check when they can see each other but the line prints the name of its origin when i tell it to print the collider it hit, i changed the name of it and then layermasked it to make sure it was actually hitting itself and it is

since i have a bunch of stuff being created at runtime and they all need to be visible to each other at all times i cant use the layer mask

how can i make the linecast stop hitting its origin??

I deal with this by putting the offending colliders into the Ignore Raycast layer just before doing the ray/linecast, then putting them back into their original layers afterwards. This works fine, although it’s a bit of a nuisance.

yeah it sure is, thanks for the advice ill give tht a shot

upon further investigation though it seems to be just the sphere coliders that have a problem with this in my scene

Another option is to have the linecast start just outside the sphere instead of in the center.

Sphere colliders for some reason collide with raycasts on the inside, while other colliders don’t. I have in the past worked around this by using a capsule collider with a height of 0.