How to create clickable NPCs?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By IranosMorloy
:warning: Old Version Published before Godot 3 was released.

Hey all,

I am currently working on a 2D space game and I would like to have an option to click on an NPC or other player to select them as my target (only 1 target at the time, of course). These targets, when selected by mouse click, will also show me their HP bar.

So the question is: how to make it work this way? I think that texture button without any texture is going to be OK for the target to be clickable/selected, but how to then get their own HP bar from their own HUD?

Thank you in advance! :slight_smile:

:bust_in_silhouette: Reply From: eons

CollisionObject2D (areas and all the bodies) have the “pickable” property, if that is enabled these will fire an input_event signal and also can use the _input_event callback (without a signal) to manage input events in their shape.

Check the “Area 2D Input Event” demo and the “3D Mouse Picking Test” (is 3D but similar to 2D).