# Find out how far an actor is in front of another actor?

I got a sequence in my level in which actors are following eacht other on a predefined path. During this sequence I want to know how far the second actor is behind the first actor. In case the second actor comes too close to the first actor I want the first actor to speed up. So it looks like they are chasing each other but the second one never reaches the first one.
My idea was to take the difference of the postion, than get this vector in local space of the first actor. In my opinion the x coordinate should now be the distance between the two of them. But somehow all I get is rubbish.
Any ideas?
Cheers

You can use Get Distance To node, or you can get the location of two actors > Subtract the first one from the other > Get Vector Length.

Drag each actor onto the map. Then select one, go to your blueprint, right click and at the top select “create reference to actor1”. Then do the same for the other actor, and right click select at the top “create reference to actor2”.

Connect those to a getActorLocation node and if you want only x,y, or z distance link up a break vector node to each of the getActorLocation nodes. Pull off the x-coordinate direction you want on both and connect those to a single int-int node. You can use an absolute value on that unless if you will be dealing with negative distances to change your speed. Set the int-int or the absolute to a variable and you can utilize that inside other blueprints!

Thanks for the answer, but when I have the distance I only know how far they are away from each other, but not if the second actor is behind or in front of the first one. The next “problem” is that both actors are flying. So they can be very close to each other on the xy plane but still have a big distance because the vertical disctance could be huge.

Hi thank fpr the answer, but at least from my understanding this solution is only working as long as the actors won’t change their direction, right?
As soon as the turn lest or right this would not work anymore?

You can do something like this to check the direction of the actors:

In this graph if the pawn is behind the other pawn and looking in a 0to 45 degree angle in the same direction then the bool is true. Otherwise it is false. I dont understand if the second issue is a problem or it is something you want to achieve though.

If you use variable distance as a vector you can then break that vector to see its x,y and z coordinates. Just hook a getVectorLength to the yellow module on the vector-vector node. Then you could use the breakVector and subtract each coordinate direction from another to get the distances of each coordinate direction.