2D click to engage in combat at appropriate attack range question

Hello, Im trying to create a top down 2D RPG style game. I have the start of the program but I can’t figure this one part out:

When I left click an enemy, the player’s sprite should recognize that the player wants to attack that enemy. The sprite will walk up to the enemy until his attack range radius touches the enemy’s hit box (collision box 2d right?). Once the player reaches that attack range, the player’s sprite should stop moving immediately and just continue attacking.

So what’s been happening is: if I left click the enemy, the player’s sprite moves on top of the enemy sprite. And engages combat this way. (While in the middle of combat) If i click and move the player’s sprite to the other side of the screen, the player automatically moves back to the enemy sprite, but this time, it stops at appropriate combat distance and continues fighting.

How do I fix this so the player sprite engages in proper combat the first time around. Thank you

Hello,
I think sharing a few screenshots/videos/gifs and some code would definitely help cracking this case :slight_smile:

To be clear here, this is a scripting question not a 2D-physics question as it’s currently tagged? It’s best to use the scripting tag for general “how to I do X in script” questions so I’ll add that tag for you.

Unless of course this is a collision detection question, it’s not really clear what specific part you’re asking about. As above, asking broad question like this is unlikely to get a useful answer as there isn’t a good answer without knowing something of what you’re doing: scripts, images/video etc.

Thanks.

Sorry for the late reply, still learning how to navigate this site. Thank you!