I’ve been seriously struggling with the same issue for days now. I’m creating a top down survival game for mobile (mostly for learning purposes) and I’m implementing a harvest resource/interact system., but I have some issues getting it to focus on the actors. I’ve been searching hundreds of tutorials but they are all using FPS and a system where you mouse at the actor you want to attack/harvest (chop tree) with a line trace.
What I want to do is pictured below:
The Player checks in a radius around it for nearest actor which is interact-able (Resource/Enemy) and highlights it (spawn circle underneath), if the INTERACT button on screen is pressed, the Player will move to highlighted actor (nearest), when under a given vector length, it will set “PlayerIsHarvesting” and start animations+attacking resource (tree), which on death will give wood.
Same goes for Attack, but instead to Enemy actor and uses a separate button.
See EPIC drawing below:
I have tried accomplishing this goal first by using an invisible collission sphere on my Character and use OnBeginOverlap. Couldn’t get it to work. Then I tried LineTraceByObject (Sphere). Can’t get it to work. Tried other line trace methods and even went to the horrible GetAllActors input. Still can’t get it to work, so I must admit defeat. _
Thanks, my resources are blueprints. This sounds like a correct way to do this. I just have no idea how to set it up. I basically just need my character to run to the three and attack it.
▼
I might be on the wrong path, but I will assume the resources are blueprints.
Could you not run a Blueprint Interface to find out which resource is in range, find that location and move towards it.
I use this in a different way, I have stores in my mobile game, and when I walk up to one, I click on it and the interface works out which store it is and activates that blueprint, opening widgets and alike.
This is using line trace under cursor, but you could use other line traces or collision sphere to do this.
This is only if your resources are Blueprints though.
Enemy should just work on begin overlap or Pawn Sensing to activate.
I can help you with the “nearest” actor part of your problem. I created a custom node that does exactly that, you input the actor you want to check the distance from (your player in this case) and feed it a reference of “actors” to sort (your resource actors/enemies) and it will give you a sorted array with the nearest actor first. You would then simply use a “Get” node and retrieve index 0. The node looks as below. All you need to do is a sphere trace for objects around your player character to generate the necessary array and the node will take care of the rest