Suppose, two actors A and B. How to check the distance between A And b, if the distance is increasing or reducing?
Announcement
Collapse
No announcement yet.
How to check a distance is increasing or reducing?
Collapse
X

Well, the most obvious solution is to get location of them both in world space, subtract location vector A from vector B and get the length of the resulting vector, then store it in some variable. On the next frame do the whole thing again and compare to the stored variable. If it is bigger then the stored one then the distance had increased if smaller then it had decreased.

Originally posted by IanBreeg View PostWell, the most obvious solution is to get location of them both in world space, subtract location vector A from vector B and get the length of the resulting vector, then store it in some variable. On the next frame do the whole thing again and compare to the stored variable. If it is bigger then the stored one then the distance had increased if smaller then it had decreased.
Thanks for the reply. But can you please show it in blueprint node? I am a newbie. I don't know how to calculate the next frame.
Comment

Hey,
let's assume you have a valid reference of ActorB in ActorA. For example through an overlap or a LineTrace.
This is how you calculate the distance between both:
If you do this one time, you have a length you will want to save and compare to a new length. If the old length
is greater than the new one, they are moving away from each other and other way round.Open for contracted work  C++/BP (incl. Multiplayer)  Tutoring  VR
My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
(Including 100+ Pages Multiplayer Network Compendium to get you started.)
Comment
Comment