how to check if there is an object "a" on the scene in coordinates (x, y)?

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

Let’s say I need to check if there is an object “a” at point A (x, y), how can I do this?

Like so?

if object_a.global_position.distance_to(Vector2(x, y)) < 1:
	print("Yes, object a is very close to (x, y)")

Thomas Karcher | 2020-12-18 23:02

Is this the best way?

ateff | 2020-12-19 07:26

:bust_in_silhouette: Reply From: Thomas Karcher

It really depends on how your scene is set up, and what exactly you want to achieve. Checking the global position (like I suggested in the comments earlier) is one option. You could also add an Area2d at that position and check for collisions with that object (provided it has a collider).