Page 1 of 1
Using BEPU Physics to simulate coin stacking
Posted: Sat Sep 26, 2015 11:02 pm
by LouisLOurson
Hello there,
I'm trying several physics engine for a proof of concept, I am trying to simulate coin stacking.
I tried several scales, weights, gravity settings, but I can't get as close to reality as I would like. I have a few problems :
- The coins seem to sink into each other when other coins are piled onto them (even with the line physicsObject.PositionUpdateMode = PositionUpdateMode.Continuous;)
- The whole structure seems a bit "wobbly" if that makes sense
Here is a gif to show what I am talking about :
https://gfycat.com/RecklessPalatableAyeaye
Here is how I am creating the coins :
Code: Select all
// Physics
physicsObject = new Cylinder(
new BEPUutilities.Vector3(position.X, position.Y, position.Z),
size.Y, size.X / 2, 10);
physicsObject.Material.Bounciness = 0;
physicsObject.PositionUpdateMode = PositionUpdateMode.Continuous;
simulation.Add(physicsObject);
The gravity is default (0, -9.81, 0)
Thanks a lot!
Re: Using BEPU Physics to simulate coin stacking
Posted: Sun Sep 27, 2015 7:10 pm
by Norbo
This is unfortunately a pretty difficult case, but there are some ways to improve it.
1) The 'sinking' effect is probably caused by softness in collision detection. Softness makes complex collisions easier to solve with fewer iterations and helps avoid instability when an otherwise-rigid system wouldn't have a solution at all. It can be turned off by setting CollisionResponseSettings.Softness to 0, though you may then need additional solver iterations for stability. Some smaller nonzero value might be good enough.
(Note that continuous collision detection can't do anything to stop objects from being forcefully shoved into each other; that's totally in the hands of the solver. CCD just stops objects from tunneling right through each other at high speeds.)
2) Increase Space.Solver.IterationLimit to ensure that a good solution can be reached. The default is 10; some particularly difficult simulations can benefit from more than 50.
3) In some cases, it's possible that the constraints will short circuit before actually reaching the iteration limit. To eliminate this as a potential cause of instability, try disabling short circuiting by setting SolverSettings.DefaultMinimumImpulse to 0.
4) Using a shorter time step duration and stepping more frequently strongly increases quality. If you can afford it, try setting Space.TimeStepDuration to something like 1/180f instead of the default of 1/60f.
5) Some penetration is allowed by default. In normal cases, this helps avoid jitter. Unfortunately, in this type of stacking, it can also allow a little lean proportional to the allowed penetration. With many stacked objects, the lean can become pronounced. This is probably the main source of the wobble-lurching.
Setting CollisionDetectionSettings.AllowedPenetration to a smaller value may help. The default is 0.01f, try values around 0.002f. I suspect going this low will also require a short time step to avoid introducing jitter.
Also scale Toolbox.Epsilon and Toolbox.BigEpsilon by the same value applied to AllowedPenetration. This forces down some termination thresholds and helps stability at the cost of some performance.
(This is an area I'd like to improve. The AllowedPenetration isn't strictly necessary if contact generation was improved, and getting rid of it would avoid this kind of weird corner case. I wouldn't recommend waiting on me to improve this though- it could be quite a few months out.)
6) The engine scales inertia tensors up artificially to improve stability. The coins may behave more like hula hoops of the same mass. Setting the InertiaHelper.InertiaTensorScale to 1 can provide more realistic rotational behavior at the cost of stability. Increasing iteration counts and shortening time step may be necessary.
Re: Using BEPU Physics to simulate coin stacking
Posted: Sun Sep 27, 2015 10:52 pm
by LouisLOurson
Thank you for your help.
I will play around wuth these parameters to see if they help.
Re: Using BEPU Physics to simulate coin stacking
Posted: Sat Oct 03, 2015 9:03 am
by JusTiCe8
Hi Norbo,
this post definitely deserve to be used as some base for a BEPU settings doc.
You've made a little mistake I guess regarding InertiaHelper, not InertiaTensorHelper, (static class in BEPUphysics.CollisionShapes.ConvexShapes namespace).
Cheers.
Re: Using BEPU Physics to simulate coin stacking
Posted: Sat Oct 03, 2015 5:21 pm
by Norbo
this post definitely deserve to be used as some base for a BEPU settings doc.
For now, I'll at least link to this post from the
documentation page. A proper overview would take more time and be mostly invalidated by v2.
You've made a little mistake I guess regarding InertiaHelper, not InertiaTensorHelper, (static class in BEPUphysics.CollisionShapes.ConvexShapes namespace).
Oop, fixed.