![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | DevDeer |
Hi, I’m making a game where you can mine ores, explore caves and more. I’m a beginner in Godot so when it comes to this stuff, I can’t do it. I want this mining mechanic to remove tiles from a tilemap while also having a cracking animation. Could anyone help me do this? (it’s a 2D game btw)
by animations do you mean hit once and the block changes and you have to hit it again for it to break or an actual animations of it braking
lewis glasgow | 2021-08-25 17:16
I mean hitting it once and the block changes and you have to hit it again for it to break
DevDeer | 2021-08-25 17:47
easy just check if the tile id is 0 if it is change it to 1 then if its one get rid of it
you might need to change the 0 and 1 around
var block_type
if is_colliding():
var point = get_collider().world_to_map(get_collision_point())
if .get_collider().get_cellv(point) == 0:
get_collider().set_cellv(point,1)
elif .get_collider().get_cellv(point) == 1:
get_collider().set_cellv(point,-1)
lewis glasgow | 2021-08-25 18:49
I’m having an error that says “The method get_collision_point isn’t declared in the current class”. Also do you know a way you can do it so that it has more tiles than once? For example: when you hit the block once, it shows the first crack, then when you hit it again it shows the second crack and finally when you hit it the third time it displays the third crack and then it would break.
DevDeer | 2021-08-25 19:13
make shore you reference the raycast node when dealing with collisions
lewis glasgow | 2021-08-25 20:16
Ok, so I referenced the ray cast node (as you can see on the code) but I’m still getting an error saying “Nonexistent function get_collider”. (Also I don’t know if I referenced it right)
if Input.is_action_pressed("click"):
state = MINE
#The code above is for the if clicked action and stuff…
if $RayCast2D.is_colliding():
var point =$RayCast2D.get_collider().world_to_map($RayCast2D.get_collision_point())
if .get_collider().get_cellv($RayCast2D.point) == 0:
$RayCast2D.get_collider().set_cellv($RayCast2D.point,1)
elif .get_collider().get_cellv($RayCast2D.point) == 1:
$RayCast2D.get_collider().set_cellv($RayCast2D.point,-1)
DevDeer | 2021-08-25 21:02
as you may know its really hard to debug without the project so if you it downloadable i will get to the bottom of it
lewis glasgow | 2021-08-25 21:16
Sorry for the late response, here you go: The mine – Google Drive
(Also the code is in the player script)
DevDeer | 2021-08-26 06:46
there you are all patched up just make shore all destroyable things have collision shapes
lewis glasgow | 2021-08-26 12:04
Thanks so much! I really appreciate the help you’ve done for the game. Would you like to be credited in the game?
(Edit: Do you know how to make it so that when the tile is broken, it would update it?
like this:
Imgur: The magic of the Internet
Imgur: The magic of the Internet
DevDeer | 2021-08-26 16:49
no thanks and here it is with tile update thing
lewis glasgow | 2021-08-26 21:01