Course contentsShow
← Unity Game Development
Lesson 205 of 8283. Physics and InteractionFree lesson

Optimizing Physics Performance for Mechanical Systems

Adjust fixed timestep settings and collision detection modes to maintain stable performance in scenes with many active joints.

In this lesson, you’ll learn how to stabilize complex mechanical assemblies by fine-tuning the physics engine's core update frequency and collision precision settings.

When you build complex mechanical systems—like multi-jointed robot arms, intricate pulley networks, or linked chain mechanisms—the physics engine performs a massive amount of calculations every frame. If your joints "jitter" or behave erratically, it is often because the physics engine cannot keep up with the demands of the constraints.

Adjusting the Fixed Timestep

The most important setting for mechanical stability is the Fixed Timestep found in Project Settings > Time. This value determines how often physics calculations occur. The default is usually 0.02 (50Hz). For intricate mechanical systems, this may be too slow, causing joints to "stretch" or oscillate. Decreasing this value (e.g., to 0.01 or 0.015) forces the engine to calculate physics more frequently, which drastically increases stability in linked joints.

Tuning Collision Detection Modes

In complex machines, parts are often packed tightly together. If a part moves too fast, it might skip over another part before the engine detects a collision (tunneling). While you have previously learned to use Continuous collision detection for projectiles, using it on every part of a complex machine is a performance killer.

Instead, follow these guidelines:

  1. Use Discrete for most parts: Keep the majority of your mechanical components set to Discrete to save CPU cycles.
  2. Selective Continuous: Only set the moving "end-effector" or the most high-speed parts of your machine to Continuous or Continuous Dynamic.
  3. Solver Iterations: If joints are still struggling, increase the Solver Iterations in Project Settings > Physics. A higher number (e.g., 10 or 15) forces the engine to be more accurate when solving joint constraints, which prevents "mushy" or loose-looking mechanical connections.
// Example: Boosting solver accuracy for high-stress mechanisms
// You can set this via script if specific mechanical modes require precision
Physics.defaultSolverIterations = 10;

By balancing a tighter Fixed Timestep with selective collision settings, you ensure that your mechanical systems remain rock-solid without causing frame rate drops across the entire project.

Key Takeaway: To stabilize complex joints, lower your Fixed Timestep for calculation precision and increase Solver Iterations, while keeping expensive Continuous Collision Detection strictly limited to high-speed moving parts.