+1 vote

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 (60 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,868 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 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 webmaster@godotengine.org with your username.