+2 votes

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! :-)

in Engine by (63 points)

1 Answer

+4 votes
Best answer

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).

by (7,922 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.