How To Get Position of touch

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

I want to know at which position the player touches on phone so i can send the bullet right there. But im confused how to use InputEventScreenTouch. I tried InputEventScreenTouch.get_position() but that doesn’t work.

Can you help

:bust_in_silhouette: Reply From: Yuminous
func _unhandled_input(event):
   if event is InputEventScreenTouch and event.pressed == true:
	   (event.position)  # the position of the touch

InputEventScreenTouch and things like InputEventKey and so on just describe the input event, so you use if event is Input... to first check if the event is the right one, before running any code on it (or else you’ll get errors).

In this case it’s also necessary to check if event.pressed == true or else the code will run also run when the player un-touches (twice in one tap).

Good luck!

Thanks good luck to you too

grafyan | 2021-07-12 05:31

:bust_in_silhouette: Reply From: Suleymanov
func _input(event):
    if event is InputEventScreenTouch:
        event.position #your touch position