favreau / bullet

Automatically exported from code.google.com/p/bullet
0 stars 0 forks source link

Kinematic Object accumulates m_deltaLinearVelocity, breaks #553

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I've attached a modified version of the basic demo that comes with bullet 
2.79. Replace the regular BasicDemo.cpp and BasicDemo.h with the versions from 
the zip file
2. Run the basic demo
3. Observe

What is the expected output? What do you see instead?
You should see one cube pushing another cube across the screen. Just before 
they reach the end of the screen they will stop. Except that the expected 
behavior is that they shouldn't stop. They should keep going forever.

What version of the product are you using? On what operating system?
bullet 2.79 on Windows 7 64 bit. Visual Studio 2010 32 bit.

Please provide any additional information below.
I've debugged this and it took me ages to figure out where the problem is. 
(especially since the behavior appeared random at first, until I figured out 
that it has to do with moving around for a while)
The problem appears to be that m_deltaLinearVelocity is never reset inside the 
object and over many frames accumulates big values. If you uncomment line 58 in 
BasicDemo.cpp (m_kinematicBody->internalGetDeltaLinearVelocity().setZero();) 
the problem goes away.

I suspect that there are similar problems with the deltaAngularVelocity and 
possibly pushVelocity and turnVelocity. In my current project I reset each of 
those values every frame, and haven't run into problems.
I assume that writing a patch for this should be quite simple, except that I 
wouldn't know where inside bullet the modifications belong.

Original issue reported on code.google.com by malteska...@gmail.com on 25 Sep 2011 at 10:16

Attachments:

GoogleCodeExporter commented 9 years ago
I'm sorry, I just realized that the description is missing an explanation for 
what is going on in the provided demo.

In the demo I've got one regular rigid body, and one kinematic rigid body. I'm 
moving the kinematic rigid body towards the regular rigid body each frame, so 
that it pushes the regular rigid body.
I also have a CollisionResolver class that's a btActionInterface. It's a much 
simplified version of the "resolve collision" part of the 
btKinematicCharacterController.

So each frame the kinematic object is placed inside the other object, then 
bullet resolves the collision for the other object, the CollisionResolver 
resolves the collision for the kinematic object, and like that the regular 
object is pushed across the screen.

Except that at some point it breaks. If you uncomment line 58 in BasicDemo.cpp 
then it no longer breaks.

Original comment by malteska...@gmail.com on 30 Sep 2011 at 3:24

GoogleCodeExporter commented 9 years ago
A kinematic object should always have mass 0. Some assert/warning should be 
added.

Can you try if setting the mass to zero fixes the problem?

Original comment by erwin.coumans on 3 Oct 2011 at 6:45

GoogleCodeExporter commented 9 years ago
Yes, if I set the mass to 0 it does not break any more. However this is not my 
expected behavior. I want a kinematic object to be able to push other things 
around. And in order to tell bullet how strongly I want it to push things, it 
needs to have a mass.

Specifically what I'm doing is that I'm speeding up or slowing down the world 
(by changing the fixed time step parameter of stepSimulation()) while player 
controlled objects are kinematic and continue to be positioned at regular 
speed. So I can slow the world down and still move around at regular speed. In 
order for objects to then react correctly to me I need to have a mass.

I think that kinematic objects should be able to have a mass. I think that to 
allow this, you simply have to reset m_deltaLinearVelocity each frame.

Original comment by malteska...@gmail.com on 8 Oct 2011 at 7:40

GoogleCodeExporter commented 9 years ago
OK, I agree with you and fix it before next release.

Original comment by erwin.coumans on 12 Oct 2011 at 8:39

GoogleCodeExporter commented 9 years ago
It should be fixed by now
http://code.google.com/p/bullet/source/detail?r=2645

Original comment by erwin.coumans on 21 Aug 2013 at 11:07