#How do i "break" tiles and make them drop stuff?
21 messages · Page 1 of 1 (latest)
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
yeah but how do i know what type of block it is?
does it needs to be a tile or a a scene?
thanks a lot!
i made a little project demonstrating how to code such mechanics in godot
https://github.com/Griiimon/2D-Mining
concepts you should be familiar with to understand the code are: custom resources, tilemaps, ray/shapecasting, physics/collision objects basics and autoloads.
the only really advanced part is the automatic generation of the tile-set, which even took me quite a while to figure out.
i do understand those concept but i wanna have the basic machanics before i start stuff like terrain generation and such
thanks a lot!
should i use a custom string data sto identify the block?
your project helped me understand a lot of things so thanks for that!
also it showed me how much work ive got 😅
Just fyi: I added some features and will be adding more until I get bored.
The repo contains a version history now for an overview
could you tell me how you handle block checking? like checking what type of block it is? would you use a directory or a match statement
In what context do you need this? In my demo, unlike minecraft, I didn't hard code any block types and haven't seen a reason to do so, yet
im trying to figure out what to do when i have many types of blocks
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...