I’ve been messing around the engine for a few days trying to get a simple moving platform/elevator to work, and eventually found out kinematic rigid bodies just does not work right.
I have a setup with a kinematic rigid body and a script attached that moves it around, and a dynamic body placed on top. So that body begins constatly bouncing from the platform when the platform moves down, or “sinking” in when going up. The same scene build in the clean Bullet 2.82 works perfectly fine, at least it seems so.
In the end I found that the body’s interpolation position is messed in RigidBody::SetPosition, thus negating the velocity approximation by the physics engine and causing movement artifacts with kinematic objects when controlled externally (and they are actually meant for that). I end up with a workaround
[pastebin]xRtXZewQ[/pastebin]
I kind of understand why this was made, but this seriously breaks the kinematic objects. I suppose there should be some more solid solution though.
BTW, why do we want to update inertia tensor on position change?
Here’s the test scene:
<removed “as an anti-spam measure, sorry”>
Well, since this is just a workaround, i thought there might be a better solution, since this one could probably cause jittering again at step zero. Not sure though. And another strange thing: the platform itself still jitter a bit when moving, you can clearly see that when stepping as a first person character on the platform. I was able to completely get rid of it by disabling interpolation in physicsWorld, but still… Any ideas?
cadaver
You should get rid of the rendering jitter by only modifying the kinematic object’s position in FixedUpdate(), so that it’s called at the same frequency as physics world simulation steps.
Andy51
Right now i am updating it in PhysicsPreStep. Is it incorrect? Tried FixedUpdate with 60 FPS, result is essentially the same
cadaver
PhysicsPreStep is the same as FixedUpdate.
Went through Bullet documentation and found out that for kinematic rigidbodies, we should not update the rigidbody transform from the scene node. Instead Bullet will continuously ask for it. This change has been pushed. So now you should be able to set the scene node position in Update() and the animation will be smooth. I noticed however that the cube bounced differently if the lift animation is done in Update() versus FixedUpdate(), that happens (I assume) because we’re now basically moving the scene node with higher frequency than Bullet keeps track of.
Andy51
Oops, i somehow did not realize we were actually changing the world transfromation of the body itself there. So, yeah, i like the new patch much better. Thank you for quick response!
And i still believe updateInertiaTensor is not needed in SetPosition, because it does not depend on body position, as far as i can see
cadaver
Checked the code and you’re right, it only uses the rotation when calculating the inertia.
Mike
When using ValueAnimation to control a node position:
when overriding node’s height in Update or PostUpdate, body position is not synched
when using FixedUpdate or FixedPostUpdate, everything is fine