#How do i "break" tiles and make them drop stuff?

21 messages · Page 1 of 1 (latest)

burnt locust
#

hello i am making a small mining game and i wanna make it so that when you hit a tile within a zone (area2d for example) it will switch a frame and after a few hits break and drops gems or rocks like minecraft, how can i implement it in godot 4?

rustic spear
#

I made it like this for my procedural mining game:

Use a ray-cast to detect tilemap blocks. set/update it from the player position to the current mouse position.
Under the condition that you start pressing left mouse button and the ray-cast is colliding with a block, start a mining_timer
after the mining_timer timeouts, remove the tile from the tilemap, but before doing that check what type of block it is. If it is e.g. gold, then instantiate a gold in the tile position. that's it
burnt locust
#

does it needs to be a tile or a a scene?

coral folio
#

You can add Custom data to each tile

burnt locust
#

thanks a lot!

heady onyx
heady onyx
burnt locust
#

thanks a lot!

burnt locust
burnt locust
#

also it showed me how much work ive got 😅

heady onyx
burnt locust
heady onyx
burnt locust
faint magnet
#

I don't think you have to check what block it is, the information is inside the block. Like create a resource with the variables hitpoints, texture and a PackedScene with what it drops. when you hit the block with your player you call the takeDamage(dmg:float) on the block and the block "decides" when it is broken and what it drops. the player does not have to know. If you have multiple weapon types you could have takeDamage(dmg: float, weapon: Enum) and again the block decides how to react to different weapon types

#

if you have blocks that interact somehow with your player, like a "sludge" block that reduces movement speed you probably wanna put those blocks in a "sludge" group and check the group the player stands on on the player

#

Oh I am sorry, you cannot just put a script or resource to a tile AFAIK, I remembered, I tried this too once. So from what you already know it's reacting to the custom data and you where asking what type to use. integer but define the types as an enum, like here: https://www.youtube.com/watch?v=k9RsnbP4a0c

Hey everyone! Welcome to the very first Dauphin Deep Dive - a series where I extract some of the extra-long technical explanations from my devlogs and throw them into their own tutorial segments. In this first episode I walk you through how to use Custom Data Layers in your Godot 4 TileSets and TileMaps. Hope you enjoy, and let me know what you...

▶ Play video