Strunk Oliver Stop My Constraints From Blowing Up
Strunk Oliver Stop My Constraints From Blowing Up
Strunk Oliver Stop My Constraints From Blowing Up
Overview
Just understanding a rigid-body solver algorithm is not enough. (google for ragdoll glitch and enjoy)
Solver Algorithm
198 kg 2 kg
198 kg
2 meter
Lets iterate
2.50
2.00 1.98
2.00
1.50
0.50
.74
~2/e
1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89 93 97
2 meter
Lets iterate
Step Distance 1 2 2 1.98 3 1.92 4 1.82 5 1.69 6 1.52 7 1.32 8 1.10 9 0.85 10 0.59 11 0.31 12 0.03
8
Relative Velocity 0.020 0.060 0.098 0.134 0.168 0.199 0.225 0.247 0.264 0.276 0.282 0.282
Distance Prev. Solver 2.00 1.98 1.96 1.94 1.92 1.90 1.88 1.86 1.85 1.83 1.81 1.79
2.50
2.00
1.50
1.00
0.50
0.00 1 2 3 4 5 6 7 8 9 10 11 12
Lessons Learned
2 constraints fighting each other iteratively solves the global problem (=bringing the boats together). We saw 2 types of iterative solvers: Strength ~ num iterations (convergence) Strength ~ num iterations2, but this adds energy
2 meter
10
7000 iterations of our beer-mug solver will move this ship by 1 meter.
Solver Type
Statement:
All quadratic/linear convergence solvers have similar strength. Solver variants found in the literature:
Position/velocity based solver. Error correction by post-projection, split impulse or Baumgarte-stabilization.
13
15
Mass Ratio:
High mass ratios require lots of solver iterations, so keep mass ratio low!
Avoid calculating the mass from density automatically:
Guessing density is tricky: What is the density of a car / a 747 ? Problem: solid vs. hollow objects -> So let your artist set the mass not the density. A tank driving either over a 10cm metal or a wooden box makes no difference: Increase your masses on small debris objects Exceptions: bullets and rockets Advice: Dont tweak mass if you dont have a problem yet.
16
Mass-Ratio in a 3d-World
In a 1d-universe, the mass ratio just depends on the mass of the objects. But games are not 1d , so 2d/3d rigid bodies can rotate. As a result the mass ratio depends on mass and inertia (=angular mass).
17
arm torso
Lets assume: All joints are limited. All joints have reached their limit. Shoulder bone is 4x smaller than arm. Mass is calculated from density.
18
Lets simplify
Lets move the pivot to the mass center of the combined arm. (in a fixed constraint we can do this without changing behavior). We see: We virtually apply a force at the shoulder bone way outside its shape. Is this bad? Yes, it results in very poor solver strength because the effective mass ratio gets extremely high (1 : 3000)
19
Effective Mass
impulse
Velocity = impulse/mass
20
Effective Mass
Impulse
Angular vel. Linear vel.
Center of Mass
Point vel. d
velocity at
= linearVel + d*angularVel = impulse/mass + d*impulse/angularMass(d) angularMass(d) = inertia/d velocity = impulse / effMass effMass = 1 / (1/mass + d2/inertia)
21
22
Total effMass at
= 33.13g
23
Summary Chapter 1
Solver strength mainly depends on: Number of solver iterations Mass ratio Rotations are bad! Angular movement reduces our effective mass and therefore our solver strength.
24
25
Angular Effects
We have 2 distance constraints (distance d) between a ball and 2 fixed walls.
d d
26
Angular Effects
If we move the walls apart, well have to move the ball to satisfy the constraints:
d d d d
27
Angular Effects
How will a perfect algorithm solve this?
d d
28
Angular Effects
We are forced to linearize the equations of motion.
d d
29
Angular Effects
Lets move the walls a little bit further:
d d
30
Angular Effects
A solver will gain energy if it overshoots too much. The likelihood of overshoots increases if the solver misspredicts the angular movement:
Because of linearization, the force direction (=Jacobian) is not optimally chosen, especially when running building the jacobianalgorithm at low frequency. Angular velocity is high compared to linear velocity. Effective angular mass is much less than the body mass and high forces are applied: inertia/d2 / mass << 1.0
31
Lessons Learned
Low inertias are the main problem for bad solver behavior!!!
They increase the effective mass ratios between bodies They lead to high angular velocities, which lead to explosions/jitter
32
Increasing Inertia
Demo
33
Increasing Inertia
Lessons learned: We can increase inertia of selected single objects easily by factor of 2 - 4 before users spot serious artifacts.
34
Inertia Visualizations
We can visualize the inertia by drawing a box which would have the same inertia.
Object Object with increased inertia
Inertia
Inertia
35
Combining Inertias
36
Combining Inertias
37
38
Lessons Learned
Increasing inertia matrix is very often quite acceptable in a game environment and artifacts are hardly noticeable. Especially true for small bodies inside a chain of constraint bodies (like shoulder bone).
39
40
Summary Chapter 2
To improve solver stability and strength:
Increase inertia Increase simulation frequency Decrease mass ratio Advice: Dont try to damp rigid bodies or the solver
41
42
Soft Contact
Demo:
44
Destruction
Idea: destroy bodies if impulses get too high.
45
Destruction
Solution 1: Estimate the contact impulse and destruct the object before running the solver:
Impulse = relativeVelocity * effectiveMass This works pretty well, except if the breakable object is blocked by an unbreakable object.
Fast bullet Unbreakable Box Destructible wall
46
Destruction
Solution 2: After running the solver: If the contact impulse exceeds a limit, break the object If implemented naively, breakable fixed objects will stop any moving object.
1st frame: Fast bullet Destructible wall 2nd frame: Stopped bullet Destroyed wall
47
Destruction
Solution 2b: Extend solution 2 with the following modifications: The solver also clips the impulses to the breaking limit. If an object breaks, move the two objects involved to the previous position.
1st frame: 2nd frame Just after solve: 2nd frame after destruct and position move:
48
Destruction
Demo
49
Summary Chapter 3
Impulse clipping in the solver allows to emulate soft, deformable or breakable materials.
50
The End
Thanks for listening, questions welcome
Solver Algorithm
51