Hi, I am working on a stacking game in Unity. When I try to put an object over another object, the object are starting to shake. If I put more objects on these object, the shaking is increasing.
I’ve made some researches about this issue and I found that we can get more stable results in 3d gaming if we enable adaptive force. However, I can not find an option to enable adaptive force in 2d physics.
Is there any advice to make 2d stacks more stable.
Do not stack much larger masses on top of others of lower mass, typically no more than a 10:1 mass ratio. The more complex the simulation i.e. more complex joints, large stacking scenarios (etc) requires more iterations for the solver. I presume you’re just using the defaults and have not tried increasing the simulation iteration counts in 2D physics settings?
Know that 2D stacking has historically been far more stable than 3D physics. Box2D has always been good at this.
Thanks for the quick response.
There are too many objects with the different sizes and I am using Auto Mass.
There is no joint in my game and I tried to increase some of the Job Options in Physics2D but I do not have any idea which one I should increase cause I could find a good document about this topic.
Now, I set all the Job Options to default and increased “Island Solver Contact Cost Scale” and “Island Solver Contacts Per Job”. To be honest, I still don’t know what these settings do.
I wasn’t suggesting you have joints, just indicating that you should try increasing the iteration count when complex joint set-ups or complex stacking is involved. This can be found at the opt of the 2D physics settings, it’s nothing to do with the experimental job options which is related to multi-threading.
Really though, there’s no specific answer here i.e. turn this on, set this value. It really depends on how complex a stack scenario this is. For simple set-ups the defaults work fine. I would certainly have a look at the project I linked.
I know that you didn’t suggest joints, just wanted to give info about my game
I lately realized that you’re mentioning about velocity and position iterations. I think my stacks are more stable now.
Could you please shortly explain what is the difference between velocity and position iterations?
For now, I don’t apply force except the gravity. In that case, would increasing position iteration work or should I should increase velocity too? I am asking that cause I can not observe minor difference between using one of them and both of them. Also, I am trying to learn more about Unity world.
I also want to ask that, if I decrease the pixels per unit count, the stacks becomes more unstable. I had tried to set PPU to 1, the boxes were literally dancing. Is there an explanation for that? Currently, I set PPU to 64 and the difference is really huge.
By the way, I had looked the project you linked, thanks again.
These two properties set a threshold when the physics solver has to solve the forces and subsequent position changes during simulation. More iterations improves the “quality” of the simulation at a potential performance loss whereas fewer iterations reduces the “quality”. Specifically however, increasing position iterations improves overlap solving whereas increasing velocity iterations improves overall stability.
Something is very odd if the resolution of your sprites affects physics because there’s no relation and this suggests that you’re using pixels as units for the physics which can cause you problems if you’re also asking for a complex simulation to be stable. The engine works with MKS (metres, kilograms and seconds) and scale is important. It’s tuned to work very well with scales of 0.1m to 10m and will continue to work with scales beyond that however to a decreasing quality. If you’re using pixels as metres then you’re likely to be handling collisions using huge objects colliding with other huge objects. It’ll also mean that the relative velocities will increase due to the larger distances involved. Of course I’m guessing here what you’re actually doing because I’ve not yet seen it.
In the end, we use Box2D as the 2D physics engine and pretty much everything that applies to that applies here so you can use information about it to apply to Unity too. Here’s the manual.