Get Distance Between Two Points?

Hello, I wonder if someone might help me?

I am spawning actors in random locations within the bounds of a volume.

I would like to use the Move Component To node in order to move the spawned item to the “ground” or, anything it comes into contact with on the way, I’ll just refer to this as “ground” for now.

The reason I would like to get hold of the distance is that I plan to give each spawned item it’s own velocity, as such the “Over Time” property of the Move Component To node will need to take a value calculated based on distance/velocity. This should prevent scenarios where items that have a great distance travel faster.

Can anyone provide me a solution for calculating the distance? I’m looking for the most straight forward approach, that’s easy for me to understand (fairly new to Unreal). I’m guessing it will involve some form of Raycast? But this would need to come out of the bottom of the spawned item and then detected the distance to the first thing it hit.

Thank you in advance for any help you can offer.

Kind regards,


Hmm, I can’t seem to edit my post… my apologies, I should have been more specific, I want the distance “directly down”, e.g. straight line out of the bottom of the spawned item, not from the pivot of one actor to the pivot of another etc…

Location1 - Location2 = Difference

Difference.length is the distance between the two locations.

Hi, thanks for taking the time to reply.

Indonunserstand the maths of it, but in this specific case, how am I obtaining location 1 and location 2.

Location 1 can be the spawned item, and it can be from its transform location, but this then needs to be calculated directly downwards into anything it directly below it, and not to the transform of the thing it hits, but the point of impact so to speak.

Rob, like this:




Is that going to go from on angles and stuff too though? e.g from the pivot of each object?

I need the distance to be measured from directly out of the bottom of the first object. It will be falling downwards and I want to detect the distance to the ground, or anything it might hit in between.

Assuming I can use the Distance(vector) node for this, I would still need to know the two positions. I can, presumably use the GetActorLocation for the first, for the spawned object, but how am I to get the position of any object that it may have directly beneath it?

This is why I assumed I’d perhaps need some kind of raycast? e.g. fire a laser out of the bottom of the object, see what it hits within a certain range/distance, get the location of that hit, at the specific hit point, then measure the distance from the start of the ray being cast to the hit point… that’s kinda what I thought - in words - but not sure how to achieve, or even if there’s a better way, in Blueprint?

This is what I’ve got at the moment, it’s spitting out values which I think look right… can you see any problems with the approach or mistakes in the nodes I’ve cobbled together?

I’ve popped off the execute lines just to make it a bit easier to view.

If you are going to provide two actor references you can use this one.

Hi all,

Not sure if this will appear, I did reply to all of your posts but they all went under moderation and don’t seem to have appeared yet. I’m not ignoring you honest :slight_smile:

I think I have managed to work out what I needed on this in the end, although I would be grateful if anyone has a better solution.

What I did was use a LineTraceForObjects and a GetUpVector but with a negative value, this allowed me to fire a ray out of the bottom of the object and reported back on what it hit beneath itself. From here I was able to get the distance between the start point of the ray and the impact location on the object it hit. With the distance now established I could divide that value by my velocity to get a period of time which was then used in the “Over Time” property of a MoveComponentTo node.

The ray only fires once, as it only needs to know the distance once to created the time period, so I think its reasonably efficient, but if you can think of a better way I’d be open to suggestions.

Hi all,

Thanks for the replies, I have replied with comments but they have not appeared, I think they are awaiting moderation.

Is this something that is less stringent after you’ve met certain criteria? It’s hard to hold a dialogue regarding the initial query etc.

Can you try to comment now?

Looks like my previous comments are appearing… let’s see if this one does too…

Much more tricky if you want to get the distance between faces. You’ll need to use some sort of combination of the distance thing ( above ) and GetComponentBounds ( GetActorBounds ), which tells you the approximate size of things.