0 votes

I just simply want to test if a position with coordinates x and y is inside Area2D or inside CollisionShape. I don't use get_overlapping_bodies function, because position is not body. Can I do that, or it is only possible with collision bodies and function get_overlapping_bodies?

asked May 5, 2018 in Engine by Marevixo (27 points)

2 Answers

+3 votes
Best answer

There are a few ways to approach this. Without knowing more about your setup, I'd probably go for the Physics2DDirectSpaceState solution using intersect_point().

You pass it a your location and it'll tell you what objects it collides with. If you're using collision layers/masks, you can be filter it so that it would only see the Area2D you care about.

var space_state = get_world_2d().direct_space_state
var result = space_state.intersect_point(point)
answered May 5, 2018 by kidscancode (17,772 points)
selected May 5, 2018 by Marevixo

That's exactly what I wanted, thanks!

0 votes

i'm not sure if i understood your question, but yes, there's a get_overlapping_areas ( ) function which works the same way as get_overlapping_bodies ( )

docs: https://godot.readthedocs.io/en/3.0/classes/class_area2d.html#class-area2d-get-overlapping-areas

answered May 5, 2018 by mateushmm14 (38 points)

Well, position is not an Area2D so that won't work... but thank you for trying to help me

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.