Why can't my enemy be both clickable and unable to be walked through by the player?

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

My first goal is for players to not be able to walk through enemies. Second, I want the enemy’s name and HP bar to appear when the enemy is clicked on. I can only achieve one goal but not both. I’m using Godot v3.0.6 & GDScript.

The relevant part of the tree~ Name (Node Type) - description:

Main (Node) - the root
-UI (CanvasLayer)
OtherHP (TextureProgress) - the targeted enemy or ally’s HP bar
-Enemy (Node) - all enemies will be children of this node
BadCat (KinematicBody2D) - my test enemy
Sprite (Sprite) - my placeholder sprite, static for now
EnemyName (Label) - his name appears over his head
CollisionPolygon2D (CollisionPolygon2D) - drawn over the sprite’s feet

~ Alternative Enemy Tree ~

-Enemy (Node)
BadCat (Area2D) - change kinematicbody2D to area2D + fix references in scripts
Sprite (Sprite)
EnemyName (Label)
CollisionPolygon2D (CollisionPolygon2D)

In Main

func _ready():

On BadCat, the input_event( Object viewport, Object event, int shape_idx) signal is connected to ../../UI :: _on_BadCat_input_event()

In UI,

func _on_BadCat_input_event(viewport, event, shape_idx):
print ("test")
if Input.is_action_pressed("click"):

If I use the KinematicBody2D version, my player sprite cannot walk through the enemy. However, mousing over and clicking does nothing. The HP bar and name remain hidden.

If I use the Area2D version, mousing over prints lots of “test” and clicking causes the HP bar and name to show. However my player sprite phases through the enemy like it’s a ghost.

How can I have it all: corporeal and clickable enemies?

:bust_in_silhouette: Reply From: hilfazer

Select Your KinematicBody2D and check “Pickable” in the Inspector.

That fixes it and is cleaner than my fix! Thanks a lot.

chimchooree | 2018-08-15 21:03

:bust_in_silhouette: Reply From: chimchooree

I got a working version after 4 days. Figures that I would get it an hour after posting here.

~ New Enemy Tree ~

-Enemy (Node)
BadCat (Area2D)

I added a KinematicBody2D child to BadCat. The second CollisionPolygon2D is a duplicate & reparent of the first. Then boom, it works. Easy fix.

If you know a better way, please share for me and other learners!