How do you make such a game?

Hey, I’m Xezlo and I’d like some help on how this type of game is made. The Quarry - Roblox
How do the blocks appear only once you mine near them, and they are always random?
Thanks

3 Likes

This may not be the answer you are looking for and I typically don’t answer these type of questions but I found it interesting. I will not be writing code on how I would do it but explain my thought process of how to do it.

The first thing you would need to do would define a grid system where the player can dig. For this example, let’s make it a 6 x 6 grid. This is a 2D grid that will in theory allow the player to continue digging down forever. Of course you could impose a limit but to keep it simple, let’s keep it infinite. There are 36 possible positions for the player to be in this grid.

A question that may come up is “Why not just create all the blocks manually or one time with a script?”. To answer that question, you could do that and that would work but it could lead to performance issues since most of the blocks you wouldn’t be able to see anyway, so why even have them exist? This also wouldn’t be able to work if you wanted an infinite depth.

Now let’s move towards what the cube is, the object you mine. A cube has 6 faces and this will be important to know. Let’s say you are on the first layer of this mine with one cube layer of cubes that we start off to define the ground. When you start mining the cube under you feet, it will need to check the cubes on each of it’s face, with like a loop. It will check if a cube exists on each face. How do we do this?

When you click on the cube, it would activate a script that would take the the cube you want to destroy. The script then could check all the directions near it. If all the cubes are the same size, you know how far away the other cube should be. You would then check if a cube is on it’s bottom, top, right, left, front, and back. If a cube isn’t there, you can load one in at that specific spot. This all could happen during the animation so when the cube is finally destroyed, new cubes are found.

There is one issue with this logic and that it will load cubes that aren’t in view of the player. Off the top of my head, I can’t think of an exact solution to that but that could be up to you to think about. Another issue is, defining if a grid spot is empty because it needs a block or if it was mined out. This is probably where you would need a script to keep track of the grid system to know if a spot was mined or not.

You would also want to validate that you are within that 6 x 6 cube and what you are trying to destroy is what is meant to be. Now onto the randomness of cubes. We could have a table in a script with all the different cubes. A random one could be found by using the random function and using that value as the index of the table to randomly choose one. You could also advance this to allow only certain cubes to show up at certain depths or depth ranges.

This is about it with my explanation, it possible that I may be wrong or missed somethings but this is my best explanation that I just thought about. Indeed, this is an interesting problem.

4 Likes

I wonder if this helps

4 Likes

Thanks for taking your time to answer me even though I made this topic in an un-professional way! I really appreciate it.

uh, Berezza made a kit for what you want
-https://www.roblox.com/library/4920625917/Infinite-Mining-Game-Kit-v4-by-berezaa