matter-js
matter-js copied to clipboard
objects won't stop moving
See https://codepen.io/anon/pen/rvGVQa for a consistent repro.
Pretty sure in real world it would have stopped much sooner. How can we tweak it so that it's more realistic?
In this case, try increasing the body.slop
e.g.
var boxProperty = {
friction: 0.7,
frictionStatic: 10,
restitution: 0.2,
slop: 0.2
};
Also, I'd say your static friction value is too high (the default is 0.5
). Balancing all of these values though is always a bit of trial and error! Other things to try: increase the density
of the lower down bodies, since placing heavy bodies on top of lighter ones can be unstable. In the complex cases, sometimes you need to also increase the engine iterations.
Thank you @liabru! That's very helpful
They don't actually stop moving if you add slop: 0.2
but keep moving very very slowly. After a minute or two the rectangles on the top fall down because they kept moving slowly to the right (without any reason).
Please re-open this issue.
This still seems to be an issue, I have a rectangle on an inclined static body and the object moves vert slowly, even on 1-degree inclined bodies.
@milan090 thanks for reporting, would you happen to be able to provide a minimal example? Specific test cases would help with improving this if possible.
I have been working on this physics simulation project. You can check the example I use here.
The code for it is here
The part of the code to focus:
const slide = Bodies.rectangle(0, sizes.height, slideLength, 5, {
isStatic: true,
friction,
frictionStatic,
slop: 0.5,
angle: angleOfInclinationInRadians,
render: {
fillStyle: "#fff",
},
});
const boxPosY =
sizes.height - (sizes.width / 2) * Math.tan(-angleOfInclinationInRadians);
const box = Bodies.rectangle(
sizes.width / 2,
boxPosY - size - 50,
size,
size,
{
angle: angleOfInclinationInRadians,
friction,
frictionStatic,
// restitution: 0.2,
density: 0.5,
slop: 0.5,
}
);
The variables used here can be adjusted on the public website link I provided earlier.
@milan090 thanks could you tell me the input values tested and the expected behaviour?
@liabru I used angle 5 degrees with max static friction and friction above 10 and it kept moving even after slowing down
@milan090 much appreciated, it often is that case that the friction values require some trial and error to get right for a given effect, which is usually what I'd recommend in games, but this does show limitations I'd love to improve.
Until then for your usage I'd recommend enabling sleeping to help bring the bodies to a full stop, or otherwise implement something similar by detecting a small velocity and then stopping the body.