I have a main bullet simulation loop in my game. A ball is thrown against a wall, bounces down some stairs and rolls across a floor. I would like to predict the simulation ahead of time. To do this I am creating a second DiscreteDynamicsWorld, creating duplicates of all my RigidBodies with the same position, orientation, linear and angular momentum as well as other settings. I step the second physics world several hundred steps.
The problem is that after a few collisions, the simulations start to diverge. The positions of all rigid bodies match exactly for the first hundred or so steps.
If I run the main simulation with a script, it completes the same way every time with no divergence.
Is this to be expected? It is possible that rigidbodies are being added in the second simulation in a different order. I am using Bullet 2.83
Determinism problem
-
- Posts: 16
- Joined: Wed Nov 25, 2015 3:34 pm
Re: Determinism problem
Are you using a fixed timestep?
-
- Posts: 350
- Joined: Sat Jul 04, 2015 10:33 am
- Location: Bern, Switzerland
Re: Determinism problem
Can you follow the pages I proposed in this post and check what you missed? There are things you can mess up especially related to stepSimulation that can make your simulation run stochastically.
http://www.bulletphysics.org/Bullet/php ... 688#p37688
http://www.bulletphysics.org/Bullet/php ... 688#p37688
-
- Posts: 4
- Joined: Tue Apr 12, 2016 7:21 pm
Re: Determinism problem
Thanks for the responses. I am using a fixed timestep. To simplify the problem I am stepping both worlds exactly the same way:inzombiak wrote:Are you using a fixed timestep?
Code: Select all
for (int i = 0; i < 500; i++){
world.StepSimulation(1/60f, 10, 1/60f);
}
-
- Posts: 350
- Joined: Sat Jul 04, 2015 10:33 am
- Location: Bern, Switzerland
Re: Determinism problem
That sounds about right regarding the time step.
Can you make both worlds add the rigidbodies in the same order? I have no idea if this breaks determinism, I would hope not, but you can easily test this.
Can you make both worlds add the rigidbodies in the same order? I have no idea if this breaks determinism, I would hope not, but you can easily test this.
-
- Posts: 4
- Joined: Tue Apr 12, 2016 7:21 pm
Re: Determinism problem
I finally had some more time to do some further testing.
It appears that the order that rigidbodies have been added to the world does affect the simulation. If I run the simulation with rigidbodies added in the same order then the results are the same. If I add them in reverse order then the results are different.
It appears that the order that rigidbodies have been added to the world does affect the simulation. If I run the simulation with rigidbodies added in the same order then the results are the same. If I add them in reverse order then the results are different.
-
- Posts: 350
- Joined: Sat Jul 04, 2015 10:33 am
- Location: Bern, Switzerland
Re: Determinism problem
Thanks for testing. Well, always learn something new every day! Can yoh make your simulation add the objects in the same order? I mean, could you solve your problem with this new insight?