Hi! In brief, I am looking for a way to obtain a vertex which is the closest point on the surface of an actor’s static mesh to an arbitrary point. I am open to both blueprint and C++ solutions.
I am basically just attempting to simulate [artificial] gravity on a large, irregular body which never moves. I just want to be able to apply a force to something like a player capsule. At each tick, the player capsule would have a force applied to it which accelerates it towards the nearest point on the surface of an irregularly-shaped closed mesh (this is the mesh, 3D mobius strip chrome - TurboSquid 1660680 - imagine this the size of a space station or moon etc). The mesh doesn’t necessarily need to be collision enabled, as it is only being used to calculate gravity – you can assume it will be totally encased / covered by other meshes, e.g. a layer of megascan dirt patches and roads and rocks all with collision enabled between the player and the gravity-reference mesh.
I’ve spent somewhere in the ballpark of 40 hours trying to figure this out so I don’t have a concise list of precisely what I have tried and what the results were. In all cases I tested by logging text / drawing debug line from the player collision capsule to the “Nearest Point.” The summary is:
-
Blueprint > Collision > Get Closest Point on Collision. I was not able to find a combination of collision/physics options (e.g. setting the static mesh as its own complex mesh, then setting Use Complex Collision as Simple) that worked for this purpose. The function would always return null unless I used a simple collision generated by unreal, which is not feasible (since this simple collision is always basically a bounding volume, and the center of the mesh needs to be “open air” like a
donuttorus) -
Blueprint > geometry script > Copy Mesh from Static Mesh > Build BVH for Mesh > Find Nearest Point on Mesh (based on this tutorial, UE5.0 Geometry Script - Using a BVH to Sample a Mesh Surface with Ray Intersections | Tutorial). This seems like exactly what I want but i was never able to get it to work. The main issue here is that every way I tried it, the thing being queried against (which i believe is the cached BVH) ended up having the same issue as Simple Collision - it seemed to be a bounding volume which fully covered the gravity-reference mesh. nowhere near enough fidelity to the original static mesh.