Context: I’m making a small experimental 2D game in which you control a rectangle that moves horizontally and other rectangular blocks fall on top of the rectangle from the sky. These blocks are simply sprites with a rectangular Collider2D and a Rigidbody2D, such that they rely completely on the physics engine for their falling and “stacking” behavior. The idea here is that the blocks would just stack on top of eachother and you’d carry them across the stage in your little raft.
Issue: My problem is that when the blocks are stacked on top of each other (again, each block is a sprite with a rectangular Collider2D and a Rigidbody2D) they move tiny little distances (like 0.001 or 0.0001 units at a time) over time, such that eventually blocks that look like they should be safely stacked will fall off the side of the blocks under them. Furthermore, the blocks underneath them will slide in the opposite direction, causing a fairly unstable stacking scenario where it doesn’t seem like there should be one.
After trying to modify basically all visible parameters for several hours (friction, linear/rotational drag, mass, etc) I tried to “dampen” these tiny changes in velocity myself via the Update script by setting the rigidbody2D.velocity to Vector2.zero if the absolute value of the velocity was within a tiny threshold, but this did not seem to have any effect whatsoever. I did something similar for rotation (by setting the rotation to zero if it’s within a very tiny threshold), and that seemed to work correctly, but for some reason the same does not work for velocity. The one thing that seemed to make things work, strangely enough, was setting fixed angle to true, but I don’t want to disable rotation since it’d be an essential part of this little game.
A few important things to note:
- This happens regardless of the moving platform: the physics issue I’m having also occurs when blocks pile onto a static, unmoving platform that is set to IsKinematic = true.
- There are no other components in the game such a animators or things like that. Yes, I did search and I did find those posts in this site.
Summary Of Question: I’m trying to figure out whether or not the Unity physics engine makes it possible to stack multiple rigidbody2D rectangular blocks on top of each other, since my (very frustrating) experience has been that these blocks, when stacked, move ever-so-gradually to the sides until they fall; I have been unsuccessful in “dampening” tiny changes in velocity via the Update method.
Any help would be nicely appreciated!