0 votes

I'm trying to get a node in a scene I have but the only reference I can use is its position. Anyway I can use that to locate the node?.

in Engine by (270 points)

I don't get it. You can't know it's position before actually getting the node to query the position info. Formulate better your question.

1 Answer

0 votes

Is a weird situation but if the Node is a CollisionObject with a shape, casting a ray/shape in that position will get what you want.

Otherwise you will have to iterate over all the nodes and check their positions (grouping or locating all the lost nodes in the same parent may speed up the search).

by (7,894 points)

The reason for this is because I'm using a GridMap and the GridMap class is less fleshed out/ half done in my opinion. My character is standing at a point on the grid but I need to get the object that's at that cell on the grid. Using getcellitem returns a int pertaining to the items in the mesh library you use not the node at that point. So fo example if I want to delete the node that my character is standing on there's no way to actually get that specific object/node from the GridMap. TileMap class is far more robust and fleshed out in contrast.

Is because there are no nodes on the gridmap, is just like a node with a bunch of meshes.

Transform the Node position to gridmap coordinates (Tilemap has a method for that but gridmap not), should be like "translation/grid size" rounded down.

With that position you can get the cell item below it (y-1), knowing the cell item you will see if exists (!=-1) and if can be removed/changed according the cell item data, to remove it just set the cell item as -1, like with Tilemaps.


I think there are requests for updates on Gridmap (which lack of a lot of features comparing to Tilemap), you can search and support these requests on GitHub to give it more attention for contributors (or add features yourself if you can).

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.