+2 votes

Hello!
Supose I have a gesture detector node which returns the position when someone tap the screen (in case of mobile game), how can I check if this position is inside an Area2D? The signals body_enter and input_event won't work for me in this case, I guess.

in Engine by (22 points)

2 Answers

0 votes

There is probably a better way to do this, but the first thing that popped into my mind was to create a collision body or area2d node without sprite, and move it to the vector position in order to trigger the Area2d event.

by (689 points)

I was thinking the same thing right after I posted this. Do you know a better way to check without a Area2D?

Researching the Area2D found that you could get the collision shape by calling get_shape. This returns a Shape object that has the method collide. This method gets the local transform, another shape to test against and this shapes transform. You can check it on the docs. Its probably no the best solution, but it's a step forward and a more elegant solution than the previous one.

+2 votes

Physics2DDirectSpaceState.intersect_point may be what you want.

Just get the state from the world and do the queries.

http://docs.godotengine.org/en/stable/classes/class_physics2ddirectspacestate.html#class-physics2ddirectspacestate-intersect-point

by (7,874 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 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.