How do you detect mouse input on individual sprites when they are stack on each other?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Luuuna

I’m trying to make a puzzle where you have to align the red marked zone on top of each circle, but I’m having trouble detecting mouse inputs on each circle. So basically I have a scene like this:

Node2D (parent)
|-- Kinematicbody1 (Big yellow cirlce)
|-- Kinematicbody2 (Medium blue circle)
|-- Kinematicbody3 (Small magenta

each of these kinematic bodies are seperate scene, if you put them together they look like this. Now I’m having trouble detecting mouse inputs on each of them, since they are stacked to one another the yellow circle detects the magenta one whenever I clicked it, I use the _input_event from the collisionobject2d. I wanted each of these circle to detect mouse input seperately from one another since I’m going to rotate them. This may seem simple but I just… can’t seem to figure it out. :frowning:

:bust_in_silhouette: Reply From: timothybrentwood

Make the parent Node2D handle all of the logic for figuring out which circle was clicked.

if smallest_circle_center.distance_to(mouse_input) <= smallest_circle_radius:
    #smallest circle clicked
elif medium_circle_center.distance_to(mouse_input) <= medium_circle_radius:
    #medium circle clicked
elif large_circle_center.distance_to(mouse_input) <= large_circle_radius:
    #large circle clicked

Thank you!! It never occured to me that you could just calculate the distance between the mouse clicks and the kinematic bodies, I think I was too tired for staring at the screen for so long :')

Luuuna | 2022-12-19 16:32