0 votes

I want to delete a node that is in certain position, how can i get a node only by knowing the position?

For example, there are many nodes, and i want to delete the one that is at 100,52 for example, how could i do it?

in Engine by (127 points)
edited by

2 Answers

0 votes
Best answer

Any object you want to check the position of should be in a group. You could then iterate through the nodes in that group and check their position against the one you're looking for.

func kill_node_at_pos( pos=Vector2(100,52) ):
    for node in get_tree().get_nodes_in_group("guffins"):
        if node.get_pos() == pos:

This most likely will be an ineffective way of doing what you're doing, unless you're quantizing your positions in some way. If the node is at position (100, 52.00001) it will fail the check.

by (1,332 points)
selected by

This will only work if your node is EXACTLY at the position you test, in pixels, without any consideration about its size or shape. That should be ok for tile-based games with no movement animation from tile to tile.

0 votes

Objects you want to check for overlaps should be or have a CollisionObject (area, body, with shape), then you can use the Physics server functions to check point, ray or shape intersections.


by (7,874 points)

In case someone needs it I put an example in another question: https://godotengine.org/qa/15407/replace-randomly-placed-objects-on-collision

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.