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.
0 votes

i have this character and a tilemap, I want to make him able to dig tunnels and mine the tiles (sort of like terraria).
But, considering code, how would I go about doing that? What are the variables that able me to manipulate the tiles individually?Is it even possible doing it with a tilemap?

in Engine by (21 points)

1 Answer

0 votes

Looking at TileMap it's pretty easy to achieve. First of all, get tile that player is digging, you will need X and Y coordinate of that tile. Then use set_cell method to change that tile to other that represents hole.

About collision... I don't know if Godot will update collision when tile is changed or if you have to do that manually. In case it's up to you, take a look at update_bitmask_area. Passing Vector2 with tile coordinates should update collision for that tile. Honestly that's my guess, can't test it.

by (381 points)

Changing the tile to -1 (empty) or another id without collider should work directly, it may take a couple of frames to update collisions, though.

If using autotiling or navigation, some extra steps will be needed to refresh the tilemap.

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.