Hello! I’d like to know what the fastest way to detect if a vector is relatively close to a mesh intersection. Using rays would be far too expensive for what I’m doing. I was trying to find a way to go through each vertex and check the vertices it’s connected to (Which I did successfully) and then check if the vector is close to intersecting a triangle between them (Which I did not do successfully)

Any help is appreciated. Thanks!

This is an interesting problem, so I poked around a bit. There is a variety of both math and code for finding the distance between a point and a triangle on the net. Here are two links to code (will have to be translated):

I also found an interesting algorithm by DarrenW at the bottom of this page:

Determine if a 3D point is within a triangle

It was interesting for two reasons. First it may give you a way of determining nearness without actually calculating the distance. Second, it may give you the tools to determine which side of the triangle the points is on (I’m slow with this kind of math and would have to plod out an answer to the ‘mays’…perhaps someone else on the list with a stronger math background can comment). I’m not sure why you are doing the calculations, but if you are calculating nearness to a closed object, determining if the point is inside the object may be important.

I also bumped into this page on the Unity Community Wiki:

3d Math functions

It doesn’t directly solve your problem, but it does have solutions that there were building block to some of the algorithms on the net.

If you are going to do this a lot (same mesh different points), it will likely make sense to preprocess the mesh and build some data structures for faster searching. Good Luck.