+1 vote

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

Godot version 3.3.2
in Engine by (19 points)

2 Answers

0 votes
Best answer
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!

by (1,002 points)
selected by

Thanks good luck to you too

0 votes
func _input(event):
    if event is InputEventScreenTouch:
        event.position #your touch position
by (327 points)
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 webmaster@godotengine.org with your username.