Open leaf-node opened 8 years ago
Hi, you have to adjust the relaxation time of the contacts to make them stable. The default relaxation time is 4 time steps, which makes the contacts nice at frame rates of about 30-60. When you decrease the time step, you must increase this number, to get the same behavior. If you decrease by a factor 10, you should increase relaxation by a factor 10. Therefore I suggest you to use:
var relaxation = 4 * spf;
The easiest solution is to set the default relaxation globally before creating the World:
p2.Equation.DEFAULT_RELAXATION = relaxation;
If you don't want to edit the global, you can set it manually for all ContactMaterials and Constraints you create.
var constraint = new p2.DistanceConstraint();
constraint.setRelaxation(relaxation);
var contactMaterial = new p2.ContactMaterial(materialA, materialB, {
relaxation: relaxation,
frictionRelaxation: relaxation
});
And don't forget to set it for the default contact material, if you use it:
world.defaultContactMaterial.frictionRelaxation = relaxation;
world.defaultContactMaterial.relaxation = relaxation;
This makes me wonder, if the relaxation should be specified in seconds rather than the number of time steps.. this would give the same result no matter what time step used.
Read more about the relaxation parameter here (eqs 9,10,11): http://www8.cs.umu.se/kurser/5DV058/VT15/lectures/spooknotes.pdf
Setting this variable works for me. : )
What about automatic internal setting of global relaxation based on the first time step duration? Would that be a backwards compatible change?
Not a good idea I think. A global constant should never change.
The .relaxation property of equations needs to be taken care of as well. Not sure if it can be made backwards compatible. But probably, in a way or another. The first step is to test if this approach is good for various time step sizes, not only small ones but also big.
I experimented with refining the time step for increased simulation accuracy. When I made the time step really small, I saw an object (that previously had no bouce) bounce very high multiple times over the same period of time.
If I increased the stiffness of the contact material in question when using the small time step, the strange bounciness reduced to no bounciness.
I think that the time step used should not have much of an impact on the bounciness of objects. Rather stiff objects probably shouldn't bounce so high.