What approach are you most comfortable with? Without seeing your code it will be difficult but something like:
In your rock sceneâs area2D make it pickable:

Then connect the input event signal to a function in your rock script.

Something like (not tested):
func _on_area2d_input_event(viewport, event, shape_idx):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
print("Rock clicked:", self.name)
So now when you click on a rock it should print itâs name.
Now here you have many ways forward. One way is to create a signal_manager autoloaded script.
create a script called signal_manager.gd and in project settings under globals add it as an autoload.
signal player_clicked_on_me(object_clicked: Node)
Now back in your rock scene just emit that signal:
# replace
print("Rock clicked:", self.name)
# with
SignalManager.player_clicked_me.emit(self)
You may want to emit self.get_parent() depending on how you structured your rock scene. Now in your player scene you need to listen for that signal:
func _ready() -> void:
SignalManager.player_clicked_me.connect(_on_player_clicked_me)
# react to the signal something like
func _on_player_clicked_me(object_clicked: Node) -> void:
var overlapping_bodies = $YourArea2D.get_overlapping_bodies()
if object_clicked in overlapping_bodies:
print("The object is inside my Area2D")
else:
print("The object is NOT inside my Area2D")
Now you will need to react to it.
#replace
print("The object is inside my Area2D")
# with something like
current_tool.take_wear_and_tear()
player.play_animation("using_axe")
object_clicked.take_damage(axe_damage_applied)
play_sound("axe_chopping_rock")
Of course what functions you call and how you call them will all depend on your code and structures etc. The important thing here is now you can tell the rock that was clicked on directly to take any damage you want to apply. You may want to apply fire_damage or impact_damage so your function might be:
object_clicked.take_damage("fire_damage", fire_damage_applied)
Now back in your rock scene, you react any way you want with your rock:
func take_damage(damage_type: String, damage_applied: int) -> void:
if damage_type == "fire_damage":
show_label("Immune to fire damage")
if damage_type == "impact_damage":
rock_health -= damage_applied
I hope that helps.
When you type these things out it seems ever so long winded, but in all honesty you are just detecting a click, passing a variable, and reacting in code to that variable. All basic stuff really so although it might read complicated (and this is not an edited and well authored teaching manual) it should be straight forward when you get the hang of passing data around.
Anyway, I hope that helps in some way. There are other ways to pass data around too, but this way would work and is relatively simple.
PS I used Area2D here as I thought that was what you were using but as @gertkeno said, if you look in the docs you will see any collision type object is fine:
PPS You donât have to use your player area2D, once you have the rock that was clicked on you can just see how far it is from your player. Again, as I said, there are many ways to do these things. This might be a better method so you can do distance attacks, ie fire an arrow at a rock.
Last edit: For overlapping bodies you may want to maintain your own list using body entered and body exited signals. Just wanted to mention that you need to properly set your masks to so your player mask actually detects your rocks.