Hello,
I’ve been trying to figure out how to check whether a GameObject is inside a curved tube. Not whether an actual collision with the tube’s mesh occurs (since moving outside the tube should be possible at any time). The closest I could get was the following:
bool withinCourse()
{
return course.GetComponent<Collider>().bounds.Contains(transform.position);
}
But this utilizes the world space bounding volume instead of the tube’s inner space.
Someone with a similar problem was suggested using multiple Capsule Colliders. But this would result in inaccuracy where ever the tube is curved, bloated, or compressed.
Is there any other way to realize this?
I had a similar problem in one of my projects, in my case I was using a spline that was converted into a tube mesh, so I could use the spline api to find the nearest point on the spline and then a simple distance check between that and the point I was checking told me if I was inside or outside the tube.
1 Like
Are you using some kind of spline to define your tube? Maybe you can try to calculate the distance to the closest point on the spline and see if it is within the tube radius? Look up “calculate distance to curved spline”
2 Likes
@MikeUpchat @PraetorBlue yes, these Tubes were built along a spline with Blender and exported as .fbx. The spline appears to be present like this:

What’s the easiest/best way to calculate the distance to it?
I used the MegaShapes asset for mine so I had the actual spline. Is what you highlighted a mesh version of the Curve? If so not sure what to suggest.