-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Colliding objects (RigidBody2d) gain energy #29639
Comments
The minimal reproduction project doesn't look like it's the same one as your screenshot. Not sure if that's also affected by the issue. |
Hmmm. I'm travelling right now - I'll take a look when I get back. Sorry. |
I updated a few things - please let me know if I have given enough information. What I am doing is very simple - and perhaps the physics engine was never meant to run continuously like this. Nevertheless, it probably should be fixed to work properly. I am thrilled it works as well as it does with a minimum of (newbie) code on my part! |
Thanks, for getting back to this. Now your project is working great - it looks like this is indeed a striking issue with the physics engine if I may say so. Reproduced the issue with just 25 balls and after 5 minutes you could already see a huge increase in energy. |
EDIT: |
Since the rigidbody simulation is a discrete algorithm, objects will overlap when they collide. When this happens, the engine will separate them by pushing them apart. When it's only a one-on-one collision, the algorithm used seems to mostly conserve energy. However, if a ball collides with multiple objects on the same frame, then it doesn't conserve energy. This can easily be seen by this example: gain-energy.mp4To combat this you can use a smaller physics timestep, which will reduce the number of times multiple objects will collide on the same frame. Continuous collision detection would probably also help, but it's not working (#9071). The algorithm could probably be adapted to conserve energy better when it collides with multiple objects, but I don't know what would be involved to get that to work. |
gas.zip
I have setup a script that prints the change in kinetic energy (calculated in the original MRP as 1/2mv^2) every 30s and did a test with 20 balls, there does seem to be a trend up, in both Godot and Jolt physics:
Jolt:
(I ended the jolt one prematurely because i fucked up and clicked and added another ball) |
Godot version: 3.1.1
OS/device including version: MacBookPro (Retinia 15", Mid 2015), 16gb, AMD Radeon R9 M370X 2048 MB, Intel Iris Pro 1536 MB, OS: MacOS High Sierra 10.13.6
Issue description:
See enclosed screenshot. With "elastic" collisions, the "energy" of the system appears to increase, and eventually, a ball disappears. Eventually, all balls except one disappear.
I have several circular balls (
RigidBody2d
) enclosed by walls (StaticBody2d
). They are given a random initial velocity andlinear_damp
,angular_damp
, andfriction
are all set to 0.Everything works fine for a while. The balls all collide with one another and the walls (like particles in an ideal gas). However, the "energy" (basically, the scalar speed) of the entire system slowly increases. After a while, a ball node completely disappears. The node is still in the list, however, and there are no noticeable error messages. Eventually, all the balls except one disappear.
Steps to reproduce:
Just run, and you will see this happen. Once running, click to add balls with random initial velocities. - try it with, say, 10 balls. Then let things progress. You will see the energy increasing, and after about 15 minutes (on my machine), a ball will disappear. After a while, another will disappear, and eventually, you will be left with a single ball, which seems to be fine as it bounces off the walls.
Minimal reproduction project:
gas.zip
The text was updated successfully, but these errors were encountered: