Search Unity

Energy Conservation

Discussion in 'Physics' started by BOLU01, Oct 23, 2019.

  1. BOLU01

    BOLU01

    Joined:
    Oct 23, 2019
    Posts:
    5
    Hey guys,

    i'm currently doing a internship for my studies.
    My task is to evaluate whether it is suitable to use Unity for physical simulations, especially regarding it's accuracy.

    For this, I have created an easy scene with a halfpipe and a sphere rolling on it. There is no own code attached to both of them. For testing purpose, I have attached PhysicsMaterial with both static and dynamic friction and bounciness set to zero to the halfpipe and the sphere. Drag and angular drag are also set to zero. In my understanding, this process should be simulated without any loss of energy.

    But when I hit play, the sphere does loose energy. And since the movement slows down quite fast, it seem's to be a quite huge loss.

    Has anyone of you ever tested something like this and experienced thes phenomenon, too? I'm curious if someone has an idea what causes this loss of energy. For me, it seem's to be a problem of PhysX.
    If so, is there another physic-engine that does conserve energy? Or an engine, that is already used especially for engineering simulation purposes?

    This is what it currently looks like.

    Halfpipe_Test.png
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Unity is not designed to simulate real time physics. While it can get accurate enough for gaming purpose, it is not suitable for scientific calculations. Game engines uses tons of simplifications for performance reasons. Smoke and mirrors.

    For such, matlab and relevant tools are more adequate. Running calculations first, then replaying in real time.

    Saying all that, using DOTS may give some benefits on the subject, but it is completely separate can of worms.
     
    SparrowGS likes this.
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    If I were to use Unity for anything like this I would use it purely for visual presentation only and keep my own simulation of what ever is relevant.

    This is more to do with physx from nvidia then unity (they actually only do the visuals, hehe).
    Maybe it will be different with the upcoming havok.. but not likely imho.

    did you try fiddling around the physics settings, rigidbody setting? (besided the friction and drag you mentioned)
    like the 'enhanced determenisim(?)', lowering fixed time and all that jazz?
     
  4. BOLU01

    BOLU01

    Joined:
    Oct 23, 2019
    Posts:
    5
    I have tried these settings. I also tried it with more solver iterations and the two-directional friction type. Nothing solved this energy-loss problem.
    It seems like this is really just a problem of PhysX.
     
  5. BOLU01

    BOLU01

    Joined:
    Oct 23, 2019
    Posts:
    5
    Does someone have any experience with the Bullet physic engine? I have read, that this engine is a bit more physical in it's calculations. Is this correct?
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    If you want best performance of bullet physics, you need use it outside Unity. Unity cripples its capabilities. That means, writing your app in separate environment.

    Either way, you will not get realistic behavior in real time in any game engine. These are not for simulations tools.

    You probably want as well for such things double precision.

    Alternatively, use DOTS with own double precision physics. Then run simulation. After simulation is done, run approximation, to render. Still, probably it wont be real time, depending on complexity.

    But question is, why you so focusing on game engine for such application in first place?
     
  7. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    332
    It is true that Physx does a lot simplification but it should obey the Conservation of Energy, more or less. At least in this very simple scenario

    Could you please attach the halfpipe? I would like to test it myself
     
  8. BOLU01

    BOLU01

    Joined:
    Oct 23, 2019
    Posts:
    5
    I did a bit more testing and changed the FixedTimestep to about 1 ms. This seems to conserve the energy much better.

    I would upload the halfpipe, but i receive an error message, that I can't upload .fbx-Files. The halfpipe was created in Blender.
     
  9. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    332
    I have tested a free falling ball of 1e3 of mass from 1000 meters high. It seems to conserve the energy

    energy conservation.gif
     
    Last edited: Oct 25, 2019
    BOLU01 likes this.
  10. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Have you changed gravity to actual earth gravity?
     
  11. BOLU01

    BOLU01

    Joined:
    Oct 23, 2019
    Posts:
    5
    This looks great! Thanks!


    Yes, gravity is like on earth.
     
  12. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    How many objects you want to simulate at one time? Did you run a stress test already?