Hi all, I am making a coin dozer game. The problem I’m experiencing is the coins are jittering when they are resting upon the surface of a moving platform. The moving platform has a kinematic rigidbody attached, and is being moved with entity.setPosition(). The coins on the other hand are dynamic rigidbodies.
Is there some sort of physics setting I can configure in order to stop the jittering from occurring? Or is there a better way to setup this simulation?
Ammo doesn’t set linear velocity of the kinematic bodies by itself. I haven’t touched it in a while, but if I remember correctly, it works so that linear velocity of a kinematic body affects dynamic bodies. I think you are expected to set it yourself to match your entity motion. Without it, the motion system doesn’t calculate the collision response correctly, which might be the cause of the jitter.
Looking at the engine sources, this is actually not supported by the engine, but can be easily added. Feel free to add a ticket to the engine repo with a feature request: GitHub · Where software is built
For now, you can set it directly on the physical body (private API, so can change in the future). Position difference between current and previous frames is your current linear velocity.
// your platform velocity
const ammoVelocity = new Ammo.btVector3(0.5, 0, 0);
entity.rigidbody._body.setLinearVelocity(ammoVelocity);
Ammo.destroy(ammoVelocity);
You can allocate Ammo vector once, re-use, and destroy when no longer needed. No need to do it every frame.
Hi, thanks for the reply! As you suggested, I tried setting the linearVelocity of the moving platform with entity.rigidbody._body.setLinearVelocity() but unfortunately, that didn’t stop the coins from jittering…
I did find that increasing the frequency of the physics fixed time steps helps a bit with the issue, but doesn’t completely eliminate it. Coins can still be seen sinking and sliding left/right while the platform moves, and the problem gets worse when coins stack on top of each other.
Hi again, thanks for taking the time to help and I really appreciate your suggestions!
I didn’t see a “mass” field available when the rigidbody is set to kinematic.
I tried setContactProcessingThreshold(value) as suggested, but unfortunately didn’t get any change in behavior. (tested both in initialize() and update(), just in case).
Any other ideas on what I might try next?
For now, I’ve set the fixed time step to 1/240. Common sense says that’s probably not ideal, but it’s actually performing surprisingly well on mobile devices.
Right, you generally can’t set a mass on a kinematic body. PlayCanvas engine doesn’t even allow it. But depending on the solver the mass may affect its result. Don’t want to dig into Ammo sources, sorry Worth a try, but I am 90% sure it won’t help. 10% is still higher than zero
The next thing to try would be a scale. Ammo is not great with very small items. I don’t know what scale you are using, but if your coins are similar or like 2 times larger than a real coin, then you are too small. Try scaling your scene like 10 times then. Also, play with your coins mass a bit if you scale.
240 steps is a bit much for older devices. It will perform well, but will heat your device. To stay cool, your target rate is 45-55.
Edit: replying from a phone, sorry for typos. If you don’t know how to set mass on a kinematic body, check how engine does it and do the same. If you can’t find it, I will point you later…