I am working on a match 3 game in Unity. The tiles have a
RigidBody2D in dynamic mode and a
BoxCollider2D. When a match occurs and the tiles are removed, the tiles above (including spawned replacement tiles) fall until they land on another tile or the tile catcher at the bottom of the board. There is a routine which checks when everything is settled (all tile rigidbodies are asleep) and then processes any new matches. However, the tiles push each other down on impact, causing a rebound and a very slow process of "settling" to their final position. The physics material for the tiles has no bounciness, so I believe this is being caused by the cumulative force of the tiles landing on each other in the physics simulation.
What I'm hoping to do is have the tiles drop the way they do (the gravity simulation is just right!) but essentially stop when they collide with another tile (i.e. not transfer any force at the point of collision). This way, they shouldn't rebound visually and also should sleep more rapidly, so matches from falling can process more immediately.
So far, the suggestions I've seen are:
- Set the velocity to 0. This doesn't work, and I assume it's because there is still being force applied.
- Detect the tile collision and set the tile to kinematic, then set it back to dynamic. I haven't been able to get this to work, as they won't turn back to dynamic. I even tried to disable the colliders until they turn back in case the collision detection keeps happening and is just overwriting it too rapidly. At any rate, this feels like a dead end.
- Scrap the rigidbodies and essentially write my own, scripted gravity simulation. I'm simply hoping to avoid this because the rest of the simulation is working great.
- Create a kinematic rigidbody on a child object, set the dynamic parent and kinematic child to ignore collisions with each other, make the kinematic collider slightly (0.1) larger so it collides first. I gather the idea here is to have the physics simulation pull down the dynamic body, while the kinematic child will stop on collision. At any rate, this also did not work, and also sounds like a bad idea.
I've considered trying to calculate the impact force and apply an equal opposing force, but I haven't figured that out yet, and I imagine at that point I should just write my own gravity simulation, per above.
I've recorded a video for visual reference on the "bounciness": https://youtu.be/aSCEJX4nzoI