determine nearest y outside of mesh from point.y inside

Is it possible to determine the distance from a point inside a mesh to the first point outside the mesh in each direction (x,y,z).

For example: I have a rigged character with an arm bone. I want to know the nearest distance in x,y,z from the arm bone transform position to the outside of the mesh. Is there an easy way to do that?

No, Raycast would have been the only solution but there are a bunch of things preventing that first you would be casting from inside out which it wont detect properly, second youd have to use a mesh collider which isnt ever reliable to begin with.

The other option would be to manually run your mesh through the mesh class where you would then have to dedicate a lot of time to figure out how to sort all that data in order to find the indicies or triangles that you are looking for (have positions closest to the position of your joint). Its doable but mind numbing.

other option thats a bit of hack in comparison

-create 3 GOs child them to the joint you are targeting

  • set them to whatever axis you are testing on either local or world (your choice)
  • set them OUTSIDE OF YOUR mesh
  • put a mesh collider on your character try to ensure it is as good as it could be, there are some importation options that affect this
  • then raycastall from those points towards your joint
  • store the info in a raycastHit
  • then do hit.distance which will give you the distance from your cast to where it hit on the mesh (assuming it worked with mesh collider(its spotty))
  • then get the Vector3 distance from your cast point position and your joint position
  • subtract the 2 distances and you get what you were looking for
  • REALLY NOT EFFICIENT TO BE DONE CONTINUOUSLY
  • not guaranteed to work 100% of the time because of mesh collider (70-90% success)