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 (20 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 (375 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 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.

Categories