This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

Hi, I´m trying to get the position of a tile inside a tile map to later set the cell to -1. The problem is that I can´t get the pos. I´m using a sprite to try to get the position. I can set a cell to -1 with set_cell() if I have the position before, but I need to delete the tile in-game when the sprite "collides" with it (get the same pos).
I tried using something like this:

var tile = self.get_cell(self.world_to_map(sprite.get_global_pos()))

But it says that the engine expects two arguments. How can I solve the problem? Thanks in anticipation.

in Engine by (56 points)

Method get_cell() wants the x and y as separate not as one vector2.

Yes, I know that, but I don`t know how to get the position on the tile map of the tiles (not the global position in the game)

Do you mean that you don't know how to get the x and y components from your world_to_map(sprite.get_global_pos()) ? You just add .x to get the x component and after a comma add the same thing for the y.
God damn I hate typing on mobile..

Thanks a lot, it worked!. I was having too much problems with this.

1 Answer

0 votes

Yeah, I'm also trying to do the same thing, so as to get the effect of the undulating tiles of Axiom Verge, I don't know if it would solve your problem but the two varaiables it expects is the int x, int y of the tile in the grid.

7,3 is the x and y

{forgive me if you could see the image I am fairly new to this thing, this was the image}

you should try the TileMap.getcellv(), you could pass your sprite or KinematicBody2D's globalposition as a parameter to it and you could get the colliding tile's index.

Then you could use something like setcell() or you could just go setcellv() from the start and bypass this process entirely almost for the same effect

by (18 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 Frequently asked questions and 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 [email protected] with your username.