Modifying the solver iteration count

Using joints, springs, and other ways to connect Rigidbodies are fairly complex simulations in physics engines. Owing to the codependent interactivity (internally represented as movement constraints) that occurs due to joining two objects together, the system must often make several attempts at solving the necessary mathematical equations. This multi-iteration approach is required to calculate an accurate result whenever there is a change in velocity to any single part of the object chain.

It, therefore, becomes a balancing act of limiting the maximum number of attempts the solver makes to resolve a particular situation versus how accurate a result we can get away with. We don't want the solver to spend too much time on a single collision because there are a lot of other tasks that the physics engine has to complete within the same iteration. However, we also don't want to reduce the maximum number of iterations too far, as it will only approximate what the final solution would have been, making its motion look much less believable than if it had been given more time to calculate the result.

The same solver also gets involved when resolving inter-object collisions and contacts. It can almost always determine the correct result for simple collisions with a single iteration, except for some very rare and complex collision situations with Mesh Colliders. It is mostly when attached objects will be affected through joints that the solver requires additional effort to integrate the final result.

The maximum number of iterations the solver is allowed to attempt is called the solver iteration count, which can be modified under Edit | Project Settings | Physics | Default Solver Iterations. In most cases, the default value of six iterations is perfectly acceptable. However, games that include very complex joint systems may wish to increase this count to suppress any erratic (or downright explosive) CharacterJoint behaviors, whereas some projects may be able to get away with reducing this count. Testing must be performed after changing this value to check whether the project still maintains the intended levels of quality. Note that this value is the default solver iteration count—the value that gets applied to any newly created Rigidbodies. We can change this value at runtime through the Physics.defaultSolverIterations property, but this still won't affect preexisting Rigidbodies. If necessary, we can modify their solver iteration count after they are constructed through the Rigidbody.solverIterations property.

If we find our game regularly runs into jarring, erratic, and physics-breaking situations with complex joint-based objects (such as ragdolls), then we should consider gradually increasing the solver iteration count until the problems are suppressed. These problems typically occur if our ragdolls absorb too much energy from colliding objects, and the solver is unable to iterate the solution down to something reasonable before it is asked to give up. At this point, one of the joints goes supernova, dragging the rest of them into orbit along with it. Unity has a separate setting for this problem, which can be found under Edit | Project Settings | Physics | Default Solver Velocity Iterations. Increasing this value will give the solver more opportunity to calculate a sensible velocity during joint-based object collisions and help to avoid the above scenario. Again, this is a default value; hence, it is only applied to newly created Rigidbodies. The value can be modified at runtime through the Physics.defaultSolverVelocityIterations property and can be customized on specific Rigidbodies through the Rigidbody.solverVelocityIterations property.

In either case, increasing the number of iterations will consume more CPU resources during every fixed update where the joint objects remain active.

Note that the Physics 2D settings for solver iterations are named Position Iterations and Velocity Iterations.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.71.142