How to make character only move if I click on a tilemap (and nothing else)?

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

Hi all, I have a tilemap where my character moves about and I have various HUD buttons etc.

Currently I click on a hud button but as the HUD sits above the tilemap, the character moves to where the button is.

How can I stop this happening so that the character only moves if I clicked on the Tilemap and nothing else?

Thanks so much

(here is my move code)

func _input(event):
if event.is_action_pressed('click'):
	if globals.activity == "walk":
		target_position = get_global_mouse_position()
		_change_state(STATES.FOLLOW)
:bust_in_silhouette: Reply From: kidscancode

You should use _unhandled_input() for your game objects, so that your GUI may consume events first.

Read this for details: Using InputEvent — Godot Engine (latest) documentation in English

Thank you so much. Totally makes sense and is now working

Robster | 2020-01-07 04:47