Find the (updated) greatest distance between actors of same class

hey,
i am currently working on an offline multiplyer game with one camera that is positioned between 2 up to 8 cars.
my idea for the camera blueprint is the following:

if number of actors (of same class) is > 1, find the greatest distance between 2 actors; else (if only 1 actor), have that actors location

so now, how can i get the (vector) value of that distance, that is constantly updated for the case of position changes or if an actor is destroyed?

(also, quick question, do you have a nice way to use logic like “if” and “else” in blueprint?)

If you search for “If” you actually find a branch which is exactly that. You provide a boolean (true / false) and then have two outputs. True and False. It’s called different but does exactly the same.

And for your issue with actors:

You can “Get All Actors of Class”, select your car and then check the distance between each of them (Absolute (ABS)(Location 1 - Location 2) ). That’s not the cleanest solution from a coding standpoint but the best we have in BP.

Cheers :slight_smile:

hey thank you, Erasio :slight_smile:

i actually found the “compare” node that gave me more likely what i wanted to use that “if for”.
so this is my (untested) math for now…
(“Arrow” is my cameras reference object)

looking a little chaotic right now^^

I would still recommend a for loop and a separate variable which represents the largest distance. It will spare you a lot of work and won’t be any worse performance wise while you are also variable in the amount of actors if you wish :wink:

First of all you need to trigger your get all actors of class. Since you want to check this all the time just hook it up to an event tick which is called each frame. Right here you should also reset your largest distance variable.

Behind it do a “ForEach” loop. in the body of that one do another “ForEach” with the same array. Compare the two “Array element” locations and if it’s larger than the largest distance variable set this as new largest distance.

wow indeed that is perfect! :slight_smile:
got it to work now with an undefined number of players.
thanks so much!

Also right now the German version of the answerhub is broken causing the comment and accept answer button to not appear. That is most certainly strange but if you change the language in your profile to English it should work properly. A fix is being worked on but yea… It might take a bit. Then you can accept the a answer (so other people don’t try to help you as well :wink: and comment instead of just answer.

Thanks and Cheers!