Simple move to actor

Hello guys.

I have a bot that uses a “simple move to actor” node. So for the goal I use “get player character”. This is working fine and the mob follows me. Now lets say I want the mob1 to move to mob2. Mob2 is of a different class. What do I plug into goal/actor, in the “simple move to actor” node? And what if there is more than one mob2 in the scene? I would like mob1 to move to nearest mob2.
Any help would be appreciated.

Could anyone help?

Hello,
Maybe a get all actors and get loc could work then compare locations to define the closest one (not sure for the best method but i remember some radar talking threads maybe usefull for that to define closest mob) and then set a variable with it and use this variable for your move to actor ?

Hi. I am not sure how to compare the locations of all the actors. When I get all actors of class, I get an array and then I dont know what to do next. Ty for reply

I tried to retrieve the post and i found this :

From answerhub : Get all actors in distance ...? - World Creation - Unreal Engine Forums, where you store the length output and the character in another variable. You compare on your loop to each new member of the array (replacing the make literal float node). Each time you compare you save the shortest one and update character when needed then you use your variable.

Edit : You’ll need to set your length valu high at start to have it working.

https://answers.unrealengine.com/questions/42693/how-can-i-get-the-nearest-actor-and-store-its-arra.html

Thanks guys. However I am not sure what to do after branch. How do I use this to set the goal in Move to actor node?

This is the first time I have to deal with arrays and loops, so a bit lost here. :slight_smile:

You create two variables, one float SelectedLength one “NearestEnemy” = “actor from class” that you selected. you set SelectedLength a high value. Then on loop, each time new length is shorter than the saved one (on true) you set selectedLength and “NearestEnemy” with actual values" from length and array element.

Then from the completed output (not from the loop body as you did) you set your “simple move to actor” with your "nearest enemy variable as target.

I let you try by yourself to discover arrays but if you have issue, don’t hesitate to come back.

Edit : The controller has to be the enemy controller. you’ll can drag it from your reference. And if your enemy is spawned you’ll may have to add a spawn default controller too to have it working.

It would be something like this :
75c1e5bcecc9ac455ed5a9bf5ac3b0632bd95ef8.jpeg

The spawn default controller is needed only if you didn’t set your enemies in level but spawned them.

I had to change a few things from your pic, but I got it working. Here is how it looks:

Looks like its time for me to get into For Loop and Array tutorials. :slight_smile: I really really appreciate your help guys. Big Thanks!!!

Happy that helped ^^ Don’t hesitate to come back if you have issues with arrays.

Will do mister! This is how it looks in action. Unreal Engine 4 Explosive decoy test - YouTube

Really cool ! Maybe opening a thread in WiP to show it ?

Too shy for that. :smiley: To be honest, I still need to make a lot of different gadget’s and to have more than one enemy model, and some actual environment, before I will dare to make a WIP thread. :slight_smile: Cheers!!!