How to get location of closest enemy pawn?
How would one go about getting the location of the closest pawn within a radius? I need the location to plug into a teleport for a special attack in my game. If someone could give me an example of the nodes to use, that would be great. I imagine I would need an array, but how I would get the location information is a little confusing to me. Also, when I "Get" from my purple array filled with actors, there is an empty plug with a number next to it. I do not know what to plug in there.
asked Oct 15 '18 at 12:09 AM in Blueprint Scripting
you need to make an array that contains all the actors in your radius. there are many ways to accomplish this such as overlaps or get all of class for example. next you need to run a test on each enemy to get its distance from the player. as you do this you also record the closest one as you go along and replace it as needed. by the time you done comparing them all you will have the closest.
below is an example of how this is done. basically you begin with an array of the enemies. then you set the first index as the closest so you have something to compare to later. then you use a for each loop to compare the distance to each enemy and if that enemy is closer than the current closest enemy you set the one being tested as the current closest.
ok now for your last question, on the get node the number you put in represents the index that you want to get from the array. basically if you have a list of things and you number each entry the index is that number. also you mentioned that you have a purple color, that means you are getting a class and not a reference which is something you dont want in this case. for what your looking to do you need a reference to the actors that exist in the scene so your variable should be of type actor reference which will be blue.
answered Oct 15 '18 at 12:52 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here