4ian / GDevelop

🎮 Open-source, cross-platform 2D/3D/multiplayer game engine designed for everyone.
https://gdevelop.io
Other
10.83k stars 850 forks source link

Balls stick to walls at low speed (Box2d issue) #1219

Open PascalLadalle opened 5 years ago

PascalLadalle commented 5 years ago

Describe the bug

Using the Physics 2 behavior, when balls are at low speed, they stop bouncing off walls, and glide along them. I tried setting Restitution at 1 and Linear damping at 0 on collision, but it's not enough. It seems to be a known issue, and the solution is to lower the Box2D setting _public static const b2velocityThreshold:Number.

4ian commented 5 years ago

Would you be able to create a quick example game to reproduce this issue?

PascalLadalle commented 5 years ago

Here goes stickyball (2).zip

4ian commented 5 years ago

I see the issue, this is problematic indeed. This might be changed by changing b2_velocityThreshold, but this seems a hardcoded constant in the physics engine: https://github.com/kripken/box2d.js/blob/master/Box2D_v2.2.1/Box2D/Common/b2Settings.h#L89

I'll see if I can recompile with a lower value, but in this case this might affect the stability of objects in other games :/

4ian commented 5 years ago

A potential workaround is to change in the scene properties the scale X and scale Y of the simulation, to something smaller like 50 instead of 100. Be sure to change also the magnitude of the forces/impulse (you'll have to test, but you'll have to increase them quite a bit). This should make less visible the improper rebounce effect. Also maybe increasing the friction/linear damping would help having the ball to stop by itself.

PascalLadalle commented 5 years ago

Scale 50 doesn't really fix it in the given example. 20 is much better, although some sliding still occurs in the right conditions. I'd rather not increase the damping, my air hockey game would look like it's switched off. 🙂

Is it possible to make that setting accessible to the user, to avoid problems with other games? Or add a checkbox that would lower the value, to avoid that gliding? 🤷‍♂ I guess gravity might create some issues with a very low value, like a bullet casing bouncing 50 times off the ground 🤔