I am making a game in the top down template that controls like leauge of legends or diablo. Depending on what I click, the character will move, move & attack, or move & pickup objects. The problem is that I cannot get ranged characters to stop moving once they reach their attack range.
I use ray tracing to determine what I am clicking on, and I compare the distance to my character and the clicked on enemy by fetching both of their locations and subtracting one from the other. The there’s a branch - if the character is in range they attack. The part that I am missing is when characters are not in attack range.
I tried using while loops, but those crashed my game every time. And I had multiple failed attemps where the player goes all the way to the enemy before attacking.
That looks exactly like what I am trying to do. Thank you very much. I just started a completely new file just to figure this out, so my setup is a fresh topdown template right now.
But, would you mind clarifying a few points?
Is the “Target” that you set after cast to enemy a variable of type actor or something else?
How would you handle the timer? Is it better to set timer by event or function name?
I tried replicating how you setup your function but mine looks different when I call it.
Here it is of the enemy type but it also does not matter - it will work the same regardless - the purpose is to check whether there is a target worth attacking. In the grand scheme of things it will matter even less as you will need to employ an interface for communication.
How would you recommend that I set the timer? Is it better to set timers by function name or event?
I prefer by event because I have fat fingers and mistype function names.
You could take it a bit further and only check for distance if there’s a target. This way this script only runs when we are outside the range.
Another way to improve the above is to add a test to see if we are already in range when clicking a target - perhaps there’s no need to even start a timer and check for distance.
I just updated it to your new graph and it works great. It also ‘attacks’ when in range.
I had a script before that attackx immediately when in range, so maybe I’ll connect that one now so that I don’t need to start a timer if in range. Thank you once more