0

My player has a collision sphere to detect any static mesh that gets close to it.

I need to find the closest point on the static meshes that are colliding with it.

I think I could use "Get Actor Bounds" to get the mesh boundaries and then use them to find the closest point but I'm not sure how to do it.

I also thought about using a trace but I would need to cast many of them in order to find the right one, and I would need a way to make the trace hit only the meshes I care about.

Right now I'm simply using the "Get Actor Location" but that gives me the center of the static mesh.

enter image description here

How should I approach the problem?

Fez Vrasta
  • 14,110
  • 21
  • 98
  • 160

1 Answers1

0

The straight forward method to get a closest point, is to compare the distance for each vertex and your point. A simple for loop and a minimum test of the distance.

Accessing mesh vertices can be a bit tricky in Unreal especially for StaticMesh. Because vertices are stored in GPU and so you have to make huge conversions. And I don't recommend to iterate over vertices if you want a real time game.

To avoid iterating over every mesh vertex, you could also check for the function : https://docs.unrealengine.com/4.26/en-US/BlueprintAPI/Collision/GetClosestPointonCollision/

By the way you could use a multiple trace with a bug sphere and iterate over every collider location. But I am not sure if the location of the break hit result is always the closest of the object.

Tendocat
  • 49
  • 3