Home » How can I clean up excessive player-created rubble?

How can I clean up excessive player-created rubble?


First of all, that game mechanic looks like it could be super fun, so congrats on thinking of it! Here are two simple solutions that could be used independently or together to solve this particular issue:

Remove Very Small Pieces

There isn’t much of a point to keeping around tiny pieces of collision that really won’t impede the player or have any real effect on the environment. Calculating the extra collision logic simply isn’t worth it, so either remove these pieces or remove collision on them.

Limit Player Cuts

Having unlimited cuts could potentially make a lot of your puzzles really simple if you can just slice every impeding object into a pile of mush. Give the player only a few cuts to play with (or make it slowly recharge over time) and you’ll likely find that it makes your puzzles more challenging in addition to eliminating the pains of dealing with collision on a thousand fragments.

Figure out your bottleneck

A few hundred moving objects should not be a problem. However, a few hundred colliding objects might be. It will take some testing, yet I believe the bottleneck you have are the collision.

By the way, about how many objects are we talking? What is the platform? A hundred objects for a mobile game is not the same as a hundred for a web game or a hundred objects for a desktop game.

Test the same game but with collisions between the cut objects disabled, and see if you get it to lag on similar amounts of objects. If that is the case, it means that the sheer amount of objects is the cause of trouble; otherwise, the collisions are the problem.

This will inform your decision on what you will do to improve performance. Not all of the ideas below will apply, and you will need testing anyway.

I will not talk about optimizing for a large ammount of objects far from the player, as the trouble seems to come when interacting with the objects.

there’s a problem when you cause them to move.

If the problem happens when interacting with the objects, it is unclear how removing not visible objects will solve it… yet, I’ll assume it might help.

I’ll just say that if objects far from the player are a problem, you could start by having smaller levels, or look into dividing the game in chunks that you can load and offload depending on where the player is going.

Out of bounds

I believe that when it comes to cleaning up rubble, the first thing to have is to remove objects that are out of bounds. For example, the piece that fell to a pit. If there is no way the player should be able to get there to see it, there is no reason to keep it around.

I will come back to this.

Make it more realistic (part 1)

When you cut wood with a saw, axe or similar tool, there will be lost material (to sawdust, shavings, etc). Even if you cut with a laser, the laser will burn some wood. In addition, for thing that are not wood there will usually be deformation around the cut, crumbling, etc.

What I am saying is that the cut is not perfect, and some material will be lost. You can model that in your game. That magic cutting red thingy has thickness. Remove that thickness from the objects (add particle effects if you feel too guilty).

This means that you will not be able to cut anything that is smaller than that thickness, in fact, attempting to do it will remove it from the game. That is good! It means that there is an upper bound the amount of rubble that there will be, and there is mechanically sound way to clean it up in game.

Change gears for small objects

This will work better if collisions are the problem.

Once an object is too small, the details of the different angles it has is less relevant. You could change to a less accurate collision mechanic. For example, you could use circle colliders.

You may treat even smaller objects without collision among themselves; only consider collision between them and agent objects (such as the player’s avatar or AI controlled characters).

Finally, very small objects could just turn into dust (particle effects).

Make it more realistic (part 2)

This will work better if collisions are the problem.

Material deforms and breaks under pressure. If you end up with long objects with very little thickness, break them down into smaller objects so they can take advantage of the solution above.

We can pretend that it had too little thickness that it crumbles and breaks when you hit it.

Merge objects

This will work better if the number of objects are the problem.

A common trick that many games use to deal with large amounts of drop that might hurt performance is to bundle drops together.

You could try something similar for small objects that are nearby each other. Have them become a single object. However, I do not mean to stick the pieces together. I mean to create a single object to handle their physics; you can still represent the individual pieces that made up the object, perhaps using techniques akin to particle effects.

Make it more realistic (part 3)

Have you heard of wind? There is wind in the real world.

Use wind to push small objects away.

I know it can sound counter intuitive, because it means small objects do not get to rest, at least not right away. Read below before you make your judgement.

You can use wind to push away small object before – or as soon as – they start to pile up. Which will work better if you are using optimizations for small objects (such are combining them or removing collisions among them).

Furthermore, if you can use wind to push items to pits or otherwise out of bounds, you can use as an excuse to remove the items. I told you I was going to go back to that. Even if you don’t, it can serve as an excuse to remove small objects that are too far away from the player, just pretend wind got rid of them while the player wasn’t looking.

You can remove some objects while the player is not looking, you have my blessing.

In addition to that, you now have an excuse to add wind, which you can add wind as part of other mechanics or obstacles of the game. You could even add into the narrative the spirit of wind that tries to keep things clean, if you are so inclined.

Note: You do not necessarily have to trigger wind when there is rubble to clean (although that would work), you probably can have wind happen at random intervals.


Some annoying beaver comes along and steal your wood!

Now you have an enemy type!

In addition, of course, they remove wood while you were not looking. You can even design it so you return to see one beaver running away with a piece of wood where used to be a pile. That would make for a memorable moment, will explain why the wood disappeared and will solve some of the performance problems you face, all at once.

It is all tradeoffs

There are limitations of the platform or the tools you have chosen, even the time and budget you have to develop the game is a limitation. You cannot make a perfect simulation of reality, yet. Nobody can.

Every developer works within the limitations that their target platform and the tools they had at the time imposed on them, and the best games had to do tradeoffs to make the game fun and engaging… even if that means less realism, in fact, often times they are fun and engaging because they are not realistic.

Let creativity come from those limitations.

Although, you can also make your game more realistic, by picking the parts of reality that are convenient for your development. Consider that sometimes removing objects that are away from the player is the part of the cost of making a fun game.

The world is discrete. You can’t render an object smaller than a pixel, so don’t allow such objects to exist. (This is similar to some of the realism points made by Theraot.)

Indeed, you might get this for free: the player specifies their cut line as essentially a discretized line on the screen. The effect of the cut is to divide every object into the sub-objects consisting, respectively, of the pixels on or below that line, and the pixels strictly above it. A one-pixel object can’t possibly be both above and below the line, so it can’t be cut by this algorithm.

If cutting all the cuttables into individual pixels would still leave you with too many objects to track, a larger minimum size might still work.

Or just don’t worry about it. If the player is prepared to spend a long time cutting objects into dust, they’re obviously not in a hurry so they can deal with the lag they caused. 😉

Related Solutions

Extract file from docker image?

You can extract files from an image with the following commands: docker create $image # returns container ID docker cp $container_id:$source_path $destination_path docker rm $container_id According to the docker create documentation, this doesn't run the...

Transfer files using scp: permission denied

Your commands are trying to put the new Document to the root (/) of your machine. What you want to do is to transfer them to your home directory (since you have no permissions to write to /). If path to your home is something like /home/erez try the following:...

What’s the purpose of DH Parameters?

What exactly is the purpose of these DH Parameters? These parameters define how OpenSSL performs the Diffie-Hellman (DH) key-exchange. As you stated correctly they include a field prime p and a generator g. The purpose of the availability to customize these...

How to rsync multiple source folders

You can pass multiple source arguments. rsync -a /etc/fstab /home/user/download bkp This creates bkp/fstab and bkp/download, like the separate commands you gave. It may be desirable to preserve the source structure instead. To do this, use / as the source and...

Benefits of Structured Logging vs basic logging

There are two fundamental advances with the structured approach that can't be emulated using text logs without (sometimes extreme levels of) additional effort. Event Types When you write two events with log4net like: log.Debug("Disk quota {0} exceeded by user...

Interfaces vs Types in TypeScript

2019 Update The current answers and the official documentation are outdated. And for those new to TypeScript, the terminology used isn't clear without examples. Below is a list of up-to-date differences. 1. Objects / Functions Both can be used to describe the...

Get total as you type with added column (append) using jQuery

One issue if that the newly-added column id's are missing the id number. If you look at the id, it only shows "price-", when it should probably be "price-2-1", since the original ones are "price-1", and the original ones should probably be something like...

Determining if a file is a hard link or symbolic link?

Jim's answer explains how to test for a symlink: by using test's -L test. But testing for a "hard link" is, well, strictly speaking not what you want. Hard links work because of how Unix handles files: each file is represented by a single inode. Then a single...

How to restrict a Google search to results of a specific language?

You can do that using the advanced search options: http://www.googleguide.com/sharpening_queries.html I also found this, which might work for you: http://www.searchenginejournal.com/how-to-see-google-search-results-for-other-locations/25203/ Just wanted to add...

Random map generation

Among the many other related questions on the site, there's an often linked article for map generation: Polygonal Map Generation for Games you can glean some good strategies from that article, but it can't really be used as is. While not a tutorial, there's an...

How to prettyprint a JSON file?

The json module already implements some basic pretty printing in the dump and dumps functions, with the indent parameter that specifies how many spaces to indent by: >>> import json >>> >>> your_json = '["foo", {"bar":["baz", null,...

How can I avoid the battery charging when connected via USB?

I have an Android 4.0.3 phone without root access so can't test any of this but let me point you to /sys/class/power_supply/battery/ which gives some info/control over charging issues. In particular there is charging_enabled which gives the current state (0 not...

How to transform given dataset in python? [closed]

From your expected result, it appears that each "group" is based on contiguous id values. For this, you can use the compare-cumsum-groupby pattern, and then use agg to get the min and max values. # Sample data. df = pd.DataFrame( {'id': [1, 2, 2, 2, 2, 2, 1, 1,...

Output of the following C++ Program [closed]

It works exactly like this non-recursive translation: int func_0() { return 2; } int func_1() { return 3; } int func_2() { return func_1() + func_0(); } // Returns 3 + 2 = 5 int func_3() { return func_2() + func_1(); } // Returns 5 + 3 = 8 int func_4() { return...

Making a circle out of . (periods) [closed]

Here's the maths and even an example program in C: http://pixwiki.bafsoft.com/mags/5/articles/circle/sincos.htm (link no longer exists). And position: absolute, left and top will let you draw: http://www.w3.org/TR/CSS2/visuren.html#choose-position Any further...

Should I use a code converter (Python to C++)?

Generally it's an awful way to write code, and does not guarantee that it will be any faster. Things which are simple and fast in one language can be complex and slow in another. You're better off either learning how to write fast Python code or learning C++...

tkinter: cannot concatenate ‘str’ and ‘float’ objects

This one line is more than enough to cause the problem: text="რეგულარი >> "+2.23+ 'GEL' 2.23 is a floating-point value; 'GEL' is a string. What does it mean to add an arithmetic value and a string of letters? If you want the string label 'რეგულარი...