Best approach to get the part of the sprite that was clicked


I’m creating a 2D turn-based RPG game where I want the player to click on the enemy to perform an attack. I want to “separate” the sprite of the enemy in, let’s say, 9 “pieces”, like a matrix. One of them would be randomly chosen as the “weak point”, so the player will cause more damage when attacking this “piece”. I already have all the battle system planned and just want to know what would be the better approach to return which “piece” was clicked by the player. Should I use 2D Colliders even if my game doesn’t have any kind of physics? Or make all the enemies’ images the same size and use the position of the click, creating a vector range for each “piece”? Or, maybe, create transparent images and arrange them on the screen to return which one was clicked on? I appreciate any help!

you may want to compute the 2d distance between a point on your sprite and the mouse possition at the time of the click, in screenspace. but, if you want to do that 9 piece approach, try to do a raycast out to the piece your clicking and if it hits that piece do something to it? That’s the best i know.

  • Zak Kaioken