- Home /
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?
Answer by lil_billy · Dec 09, 2012 at 03:58 PM
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)
I think that's a great idea to use the three game objects as sensors. I'll try it.
Your answer
Follow this Question
Related Questions
Receiving String from Variable in other Object 3 Answers
Position inside or outside of custom shape (select object if inside custom drawn selection) 0 Answers
how can i detect when my gameobject is completely inside of another gameobject? 2 Answers
Get position of the centre of each grid tile 1 Answer
How can I consistently get the rectangle bounds around a mesh? 2 Answers