Replacing a group of objects with a gestalt of them

For some context, I’m working on a game sort of like Minecraft. However, every cubic “block” follows dynamic physics and can be moved around by the player and other forces.
When running large chunks of terrain, this idea in practice would pretty much melt any computer. To help avoid this problem, I intend that whenever a 2x2x2 mass of similar cubes forms, the game would replace them with a single scaled up cube of the same material.

Here’s what I’m picturing:

Screenshot 2024-04-22 at 12.34.56 PM

I’ve tried for many hours implementing this through Raycasting each direction from a certain cube and offsetting the origin to check for the cubes on the opposite side. That method always gets so complicated near the end that my code is unreadable, plus, it simply isn’t practical given how fast the code needs to run.

How would you elegantly detect a 2x2x2 mass of cubes of the same scale carrying the same tag? Also, how many physics based objects can Unity handle? (Wondering if a tech demo would even be possible)

I’m using Unity’s Visual Scripting but understand C# enough to where I can probably translate your answers from C# over to Bolt.

Thank you so much for your help!

1 Answer

1

f you are doing a minecraft style game, first thing you need to remember is that backs of cubes shouldnt be rendered.

Having that in mind, you should try a different aproach:

  • Instead of using tags, make a list of cubes instantiated and a string list of what theyre called “fire,
    ice, wood, etc…”;
  • Assuming only the front faces are visible and since you now have a list of current available cubes,
    get the transform or material components;
  • Only change visability or spawn the surface cubes “You could now write a function to check if its the last on the y axis or at 1 meter distance of the current position, any way yould like”
  • Merge the distant cubes to save performance with a condition of having anything that could affect
    their state so its not constantly merging on update;

Should I use plane objects for the rendered sides of cubes and for collision? Also, with the dynamic physics, how could I apply that with this method? Great idea for spawning terrain as the player mines downward and replacing the tag system with a list, will definitely keep those in mind. Thank you so much for the help WintersBane!