Shortest distance between meshes

Hi,

I try to create a tool to measure shortest distance between two meshes (StaticMeshActor exactly).
What is the best solution to do that ?

Obviously, the distance between actors doesn’t work because it refers to the center (or pivot).
I also tried to iterate on vertexes but it depends on how the meshes were created.

Thank you

1 Like

If these StaticMeshActors have complex collision you could use sphere traces.

Sphere trace from object A toward object B and save the first overlap location.
Sphere trace from object B toward object A and save the first overlap location.

Closest distance between the objects is VectorLength of Overlap1 - Overlap2.

I understand what you want to do but it doesn’t work for certain case.
For exemple, in this picture (green circle are pivots), it doesn’t work.
Because the shortest distance between black and red actors isn’t “between” pivots.

1 Like

You will have to throw some math at this problem. If you create functions that describe the surfaces of the objects, you can then subtract these functions from one another and calculate the first derivative. Solve the resulting function for [insert function] = 0. This is the only way to do this mathematically without checking every possible vector by hand. (The only way I can think of right now, anyways). Feel free to ask more questions regarding this.

1 Like

It seems to be a very difficult option for complex meshes.
With that solution, i need to define a function for each shape, is there a method to define it automatically ?

I think that solution can’t respond to my problem but it’s a good idea anyway.

1 Like

"is there a method to define it automatically ? "

Well, nothing that would be a reasonable amount of effort, I fear.

I think the question here is: how accurate do you need this to be? What you could try is: use multiple expanding sphere collisions at the objects’ surface points. Once one of the spheres overlaps, it’s radius is your distance.

1 Like

Yeah, i tried this, It’s what I am using but how to get all surface points ? I’m currently using the vertexes but on specific mesh (plane, cube, cylinder…), vertexes are too far of each other…

1 Like

well… “all surface points” is not wise, since that would mean minimum increments, with vectors being defined as 3 floats, that is a lot of points. Generally the faces between vertices are linear, so you could move along the edges of the object. What are you trying to achieve with this? Maybe we are over-complicating this.

1 Like

Sure,

I’m trying to create some tools for an application.
For exemple, i have a constraint on certain objects, they have a minimum distance to others and i want to detect all the ojects inside this minimum distance.
Or, I want to find the nearest object of a selected mesh.

1 Like

I understand

I need to highlight the actor, i need a list of all objects, and potentially many other things.

1 Like

But what do you do with that information? Do you move the actor? Do you change it’s colour? Do you need the distance for some kind of simulation? I need a bit more information to help you out here.

EDIT: (I am asking because materials can use distance fields, but I don’t think that information can be extracted into blueprints without a lot of work.)

1 Like

You could add custom collision shapes for the meshes by hand and adjust the size to (roughly) fit the distances you want, that way you can get all the actors inside that distance. The DistanceToNearestSuface material node might help with highlighting how close one point of a surface is to the next surface. You can also look into the SceneTexture node and potentially work with Scene Depth.

In the end, if you want high accuracy you will have to do a lot of work.

1 Like

Thank for your advice,

I will try this and if I find something, I’ll post the solution here and mark as resolved.