Topic was automatically imported from the old Question2Answer platform.
Asked By
Robster
So much fun
Godot 3.0 Stable
I’m making a lemmings type concept. I will be using a RigidBody2d as my “lemming” and I want the ground to be destructible.
Unless I can be swayed otherwise I’m planning on using a bitmap somehow to destroy the landscape. So for example, if I drop a bomb, it will hit the landscape, create a 2D circle that is used to eat away at the bitmap and therefore a hole/dent is created.
I’ll work toward that, but I’m thinking. If I do use that method, how can I get the RigidBody2d to follow the bitmaps outline? I can check for transparency I’m guessing and I found an example where someone manually moved a sprite about based on transparency allowing it, but that’s not using a RigidBody2D.
Hi! I would like to change my previous answer, as it was not thought enough
To make a destructible terrain, I would definitely use quadtrees. You have to divide your terrain into squares (which is convenient if you use tilemaps). Then, when there is a “hit”, divide the square into smaller squares, and remove the bigger one. Keep doing that every time a square is hit. At the end, you will have a well sculpted terrain
In the example here I used a large final size, but you can descend down to 1x1px² to be more precise (although it may be more resourceful!)
Now you have to deal with collisions and texture.
Make the main square a StaticBody2D, with a collisionShape2D and a Sprite. When you divide it, copy it into 4 new StaticBody2Ds, and adapt the collisionShapes. For the texture, use Sprite regions, and adapt it to the size of the newer blocks.
Also, you may want to optimize the algorithm a little bit to reduce the number of subdivisions. In my example, you can see that many subdivisions “inside” the green could have been avoided.
I hope you achieve what you’d like!
Hi and first of all thank you for the amazing answer and also sorry for the delay in reply. I saw this a few days ago but work has had me pinned down and it’s the weekend so I’m trying to sneak an hour in to absorb what you’ve said.
I’ll drop back here with a proper response after having a look through all the content you just provided.
I really again want to say thanks. It’s an incredible answer.