0 votes

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

Godot version 3.2.3
in Engine by (41 points)

Like so?

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

Is this the best way?

1 Answer

0 votes

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).

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