Stable Simulations#
A simulation is unstable when objects shake, sink into each other, fly apart, or pass through each other. The changes on this page fix most cases.

What to Change#
You See |
Change |
Setting |
|---|---|---|
Stacks lean and fall, joints stretch, objects shake |
Take several smaller steps for each step your program needs, as in the figure. ovphysx never splits a step on its own. |
The |
Stacks sag, objects sink into each other, joints drift apart |
Give the solver more iterations, the passes it makes in each step to correct positions. More iterations cost time. |
|
A heavy object sinks through light ones |
Keep the masses of objects that touch close to each other. |
|
Objects jump apart at the first step |
Place the shapes so that they do not touch at the start. |
The positions in your scene |
Joints jitter or shake, or a gripper pushes away what it holds |
Use the lowest stiffness that reaches the target, enough damping that the joint does not swing past it, and a force limit. Drives explains them. |
The drive’s |
A fast object passes through a wall or the ground |
Turn on continuous collision detection (CCD), which looks for contacts between steps. Try speculative CCD first, because it is cheaper. If objects still pass through, also turn on sweep CCD. |
Speculative: |
A thin object, or a somewhat fast one, passes through another |
Raise the contact offset of the moving shape, so that contacts start at that distance. Larger offsets cost time. |
|
A setting whose name starts with physx, such as physxRigidBody:enableCCD, works only when the
matching API schema, here PhysxRigidBodyAPI, is applied to the prim.
Tests with simple box scenes showed the following:
A 1,000 kg box sank straight through a stack of 1 kg boxes, even with 64 iterations. A 100 kg box sank about 1 cm.
A 10 cm box at 10 m/s passed through a 2 cm wall. A contact offset of 0.3 m stopped it. At 30 m/s, only CCD stopped it.
A Stack That Stands#
The figure comes from this program, stable_simulations_stack.py. Its scene allows the solver one position iteration, which makes
the stack of six 0.5 m boxes fragile. It simulates 5 s with 1/60 s steps, then with 1/240 s steps.
import ovstage
from ovphysx.population import physics_population_descs
from ovphysx import PhysX
from ovphysx.samples.python_samples.schema_support import physx_schema_paths
from ovphysx.types import SimObjectType
def box(i):
"""A 0.5 m box, the i-th from the bottom of the stack."""
return f"""
def Cube "Box{i}" (
prepend apiSchemas = ["PhysicsRigidBodyAPI", "PhysicsCollisionAPI"]
)
{{
double size = 0.5
double3 xformOp:translate = (0, 0, {0.25 + 0.5 * i})
uniform token[] xformOpOrder = ["xformOp:translate"]
}}
"""
# Six boxes stacked on the ground. The scene limits the solver to one
# position iteration, which makes the stack fragile.
SCENE = """#usda 1.0
(
metersPerUnit = 1
kilogramsPerUnit = 1
upAxis = "Z"
)
def Xform "World"
{
def PhysicsScene "PhysicsScene" (
prepend apiSchemas = ["PhysxSceneAPI"]
)
{
uniform uint physxScene:maxPositionIterationCount = 1
}
def Plane "Ground" (
prepend apiSchemas = ["PhysicsCollisionAPI"]
)
{
uniform token axis = "Z"
}
""" + "".join(box(i) for i in range(6)) + "}\n"
def top_box(physx):
"""Return the x, y, z position of the top box."""
with physx.read_sync(
SimObjectType.RIGID_BODY, ["position"], pattern="/World/Box5"
) as result:
x, y, z = result.groups[0].tensors[0].numpy()[0]
return float(x), float(y), float(z)
def simulate(steps_per_second):
"""Simulate 5 s in steps of 1 / steps_per_second s.
Report how far the top box moved.
"""
stage = ovstage.Stage("stack")
ovstage.population.open_usd_from_string_with_desc(
stage, SCENE, ordinal=1, time=ovstage.population.DEFAULT_TIME, descs=physics_population_descs(rendering=True)
)
stage.advance_write_floor(ordinal=1).wait()
physx = PhysX()
physx.wait_task(physx.attach_ovstage(stage, read_ordinal=1))
x0, y0, z0 = top_box(physx)
for _ in range(5 * steps_per_second):
physx.step_sync(1.0 / steps_per_second)
x, y, z = top_box(physx)
sideways = ((x - x0) ** 2 + (y - y0) ** 2) ** 0.5
print(
f"1/{steps_per_second} s steps: top box moved {sideways:.3f} m sideways, "
f"height {z0:.3f} m -> {z:.3f} m"
)
physx.wait_task(physx.detach_ovstage())
physx.destroy()
stage.destroy()
ovstage.population.register_usd_schemas([str(p) for p in physx_schema_paths()])
simulate(steps_per_second=60)
simulate(steps_per_second=240)
It prints:
1/60 s steps: top box moved 4.201 m sideways, height 2.750 m -> 0.250 m
1/240 s steps: top box moved 0.003 m sideways, height 2.750 m -> 2.746 m
With 1/240 s steps, four times as many, the same scene stands. Smaller steps often let a scene keep fewer iterations.
More Detail#
Drive Stability tunes drives in depth, and Joint Armature steadies articulations with very light links.
Collision Behavior Guide covers contact quality.
Joint Parameter Tuning: Robotiq 2F-85 tunes a gripper.
Known Physics Limitations lists cases without a full fix.
Physics Solver, Continuous Collision Detection, and Rest and Contact Offsets list the settings.
Next: Fast Simulations.