am currently stuck trying to figure out how to make mining mechanic similar to terraria
i need help making mining mechanic
porg13 but what does your game look like ATM?
the game is in its early protype stage were am trying refine the main mechanics
porg13 SYNERGY! DISRUPTIVE! INCENTIVIZE!
you are not telling us anything man.
if you have a game, don't be afraid of showing it, even if it looks like "dogs*it", all games look like that at "early prototype stage".
but we need to know if it's a 2D, 3D, 1D, what do you have done already or plan to do with it?
- Edited
sorry about that game i have in mind is a 2d sidescroller mining exploring these are some of the screenshots the second image is the the of my pickaxe were i want to have all the mining code.
forget to say but i already handled the multi weapon system
- Edited
porg13 the first script is extending a resource. you should use a node instead since you have to interact with the world.
I'm not familiar with tilemaps, but you want to locate the current tile that is being mined and then erase it or replace it. and you can use a scene for animating the tile being dug.
the first thing I found is the erase_cell
method which seems to delete a tile:
void erase_cell(layer: int, coords: Vector2i)
Erases the cell on layer layer at coordinates coords.
If layer is negative, the layers are accessed from the last one.
https://docs.godotengine.org/es/4.x/classes/class_tilemap.html#class-tilemap-method-erase-cell
and set_cell
which sets the tile and can also be used to delete it:
void set_cell(layer: int, coords: Vector2i, source_id: int = -1, atlas_coords: Vector2i = Vector2i(-1, -1), alternative_tile: int = 0)
Sets the tile identifiers for the cell on layer layer at coordinates coords. Each tile of the TileSet is identified using three parts:
The source identifier source_id identifies a TileSetSource identifier. See TileSet.set_source_id, The atlas coordinates identifier atlas_coords identifies a tile coordinates in the atlas (if the source is a TileSetAtlasSource). For TileSetScenesCollectionSource it should always be Vector2i(0, 0)), The alternative tile identifier alternative_tile identifies a tile alternative in the atlas (if the source is a TileSetAtlasSource), and the scene for a TileSetScenesCollectionSource.
If source_id is set to -1, atlas_coords to Vector2i(-1, -1) or alternative_tile to -1, the cell will be erased. An erased cell gets all its identifiers automatically set to their respective invalid values, namely -1, Vector2i(-1, -1) and -1.
If layer is negative, the layers are accessed from the last one.
https://docs.godotengine.org/es/4.x/classes/class_tilemap.html#class-tilemap-method-set-cell
and also set_cells_terrain_connect
and set_cells_terrain_path
which appear to work with automatic terrains
void set_cells_terrain_connect(layer: int, cells: Array[Vector2i], terrain_set: int, terrain: int, ignore_empty_terrains: bool = true)
Update all the cells in the cells coordinates array so that they use the given terrain for the given terrain_set. If an updated cell has the same terrain as one of its neighboring cells, this function tries to join the two. This function might update neighboring tiles if needed to create correct terrain transitions.
If ignore_empty_terrains is true, empty terrains will be ignored when trying to find the best fitting tile for the given terrain constraints.
If layer is negative, the layers are accessed from the last one.
Note: To work correctly, this method requires the TileMap's TileSet to have terrains set up with all required terrain combinations. Otherwise, it may produce unexpected results.
void set_cells_terrain_path(layer: int, path: Array[Vector2i], terrain_set: int, terrain: int, ignore_empty_terrains: bool = true)
Update all the cells in the path coordinates array so that they use the given terrain for the given terrain_set. The function will also connect two successive cell in the path with the same terrain. This function might update neighboring tiles if needed to create correct terrain transitions.
If ignore_empty_terrains is true, empty terrains will be ignored when trying to find the best fitting tile for the given terrain constraints.
If layer is negative, the layers are accessed from the last one.
Note: To work correctly, this method requires the TileMap's TileSet to have terrains set up with all required terrain combinations. Otherwise, it may produce unexpected results.
the method get_cell_atlas_coords
appears to be the way to obtain the coords of a tile using a position
https://docs.godotengine.org/es/4.x/classes/class_tilemap.html#class-tilemap-method-get-cell-atlas-coords
Vector2i get_cell_atlas_coords(layer: int, coords: Vector2i, use_proxies: bool = false) const
Returns the tile atlas coordinates ID of the cell on layer layer at coordinates coords. Returns Vector2i(-1, -1) if the cell does not exist.
If use_proxies is false, ignores the TileSet's tile proxies, returning the raw atlas coordinate identifier. See TileSet.map_tile_proxy.
If layer is negative, the layers are accessed from the last one.