-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible restitution/force bug #394
Comments
Strange. My guess is that it has to do with slight fluctuations in FPS for a few frames after page load (e.g. while the browser is doing stuff like JIT), which will cause different results because Try starting the runner after letting the framerate settle for a second or two: setTimeout(function() {
Runner.run(runner, engine);
}, 2000); Seems to give the same result every time for me after doing that. Alternatively use a fixed delta for the runner: var runner = Runner.create({
isFixed: true
});
Runner.run(runner, engine); In fact this shows there's a pretty huge difference! I had to increase the force to make them reach the bottom, but it remains consistent every time. I wonder if I should somehow integrate these findings into the runner or examples. |
@liabru Thanks for the reply. This is just an example to present the problem using only restitution (no custom mass, friction, etc.). I have the same problem in my game that isn't using Matter.Runner but Matter.Engine only. I tried playing around with slop, friction, setting restitution to static bodies, etc. but I couldn't find any solution. I don't see such a problem in P2: http://codepen.io/and_re/pen/evrgLG but I had to set stiffness to Number.MAX_VALUE |
Can you explain exactly what the problem is then? Since with
How are you calling |
I'm expecting circle bodies with restitution 0, 0.5 and 1 to bounce like this: I'm using https://github.com/sethvincent/gameloop on the server (delta in ms): const gameloop = createGameloop({
fps: 60,
})
gameloop.on('update', function (delta) {
Matter.Engine.update(engine, delta * 1000)
}) |
Is |
From this file it looks like delta is always consistent (the same value): https://github.com/sethvincent/gameloop/blob/master/index.js But is it really possible that even a small difference in delta could cause 3 completely different results as you can see on my gif? |
I just updated my codepen according to your suggestions but the problem still exists: |
Thanks for the update! Looks like you are right and I think I've tracked down the cause. It appears to be because the resolver considers slow collisions to be 'resting' under a certain threshold. It's possible to lower the threshold and it seems to fix the issue:
It's entirely possible that the default is set a little too high, so maybe I need to review it. Tell me if that works for you. |
@liabru Thank you so much :D Matter.Resolver._restingThresh = 0.001 really helps. If you are curious why it was so important for my game you can check it out here (it's still under development): |
No problem, neat game! Send me a message when you release it. |
I'm applying some force to 6 circles in a world without any gravity.
I'm rerunning the same code multiple times and I get 3 completely different results (the last one is at the end).
http://recordit.co/Amjrsw7ct9
Source code (you may need to adjust the value of defaultForceY):
http://codepen.io/and_re/pen/YZaBXV?editors=0010#0
@liabru is it because circles aren't normal circles but approximated using polygons?
http://brm.io/matter-js/docs/files/src_factory_Bodies.js.html#l121
The text was updated successfully, but these errors were encountered: