Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to eliminate the vibration?

Discussion in 'General Graphics' started by JamesW940516, Sep 4, 2023.

  1. JamesW940516

    JamesW940516

    Joined:
    May 19, 2023
    Posts:
    31
    Hello
    I have a question which is related with Unity Physics.
    This is not a physics problem honestly.
    I simulated a physics mechanism for me cells of personal project.
    This is all about geometry and math and time and delta time.
    So they do not have any built in Unity Physics and Collisions and Rigidbody at all. Therefore it is impossible to have the benefit of Unity built in physics such as collision detection.

    The following is the logic what I have implemented.
    Every cell has radius.
    So, if one cell is inside of radius of another cell, they should be pushed to outside of radius each other. I think this is a clear logic.
    So, based on the positions and radiuses of cells, I calculated the displacement vector value that each cell should be displaced when they are inside of radius each other.

    Everything was perfect except for the frame rate.
    The problem is the frame rate should be infinity in this case theoretically.
    In real life, the Rigidbodies can not be inside of each other.
    This is because the reaction force is affect the Rigidbodies in real time.

    I can not make the frame rate to be infinity.
    It is about 60-120 fps.
    Because of this, an vibrating effect is occurred.
    At [N] th frame, a cell pushed to the north and at [N+1] th frame, a cell pushed to the south, when the cell is in middle of two other cells.
    [N+2] th, to the north, [N+3] th, to the south.
    This is the vibrating.

    I have to eliminate this vibration from my cell.
    I have attached to the code part I implemented and a video which is showing the terrible vibrating.
    Let's discuss about this, and please help me to overcome this obstacle.
    Thank you.

    Code (CSharp):
    1. if (aBubbleNumber == (short)(cCellSlotIndex / EntityManager.PIECE_COUNT))// when cells are siblings
    2. {
    3.     if (aCellModel.qCellCoolDown < 0.0f && cCellModel.qCellCoolDown < 0.0f)// when one cell can consum the other cell
    4.     {
    5.         if (aCellModel.mCellMass > cCellModel.mCellMass)
    6.         {
    7.             if ((aCellModel.mCellLocalPosition - cCellModel.mCellLocalPosition).sqrMagnitude < aCellModel.nCellRadiusSquared)
    8.             {
    9.                 cCellModel.Change_CellActive(false);
    10.  
    11.                 aCellModel.Change_CellMass(aCellModel.mCellMass + cCellModel.mCellMass);
    12.             }
    13.         }
    14.     }
    15.     else// when one cell can not consum the other cell, they should be pushed each other
    16.     {
    17.         float distance = (aCellModel.mCellLocalPosition - cCellModel.mCellLocalPosition).magnitude;
    18.         if (distance >= aCellModel.nCellRadius + cCellModel.nCellRadius) continue;
    19.  
    20.         float magnitude = (aCellModel.nCellRadius + cCellModel.nCellRadius - distance) / (aCellModel.mCellMass + cCellModel.mCellMass) * cCellModel.mCellMass;
    21.         Vector2 displacement = Vector2.ClampMagnitude((aCellModel.mCellLocalPosition - cCellModel.mCellLocalPosition), magnitude);
    22.  
    23.         aCellModel.Change_CellLocalPosition(aCellModel.mCellLocalPosition + displacement);
    24.     }
    25. }
    https://drive.google.com/file/d/1VPCDg0_dn0oeTdAtLPi3BcZodxob7CgQ/view?usp=sharing
     
  2. cosmochristo

    cosmochristo

    Joined:
    Sep 24, 2018
    Posts:
    250
    have you checked that (short)(cCellSlotIndex / EntityManager.PIECE_COUNT) is producing the numbers you expect?
    Perhaps print them out to be certain.
     
  3. JamesW940516

    JamesW940516

    Joined:
    May 19, 2023
    Posts:
    31
    Thank you very much for your advice.
    The part you pointed is working correctly.
    They detect that they are siblings or not.

    I think there is a kind of misunderstanding due to my bad description.
    What I meant was the vibrations between siblings.
    This comes from fact that they are not real Rigidbodies.
    I have experimented with Rigidbodies and there wasn't this kind of vibration.
    However, Rigidbodies cannot be used because they cannot overlap each other when they should.
    So, I made this "hand made Physics".

    The only problem is the vibration.
    I tried some solutions but did not work.
    Could you help me?
     
  4. cosmochristo

    cosmochristo

    Joined:
    Sep 24, 2018
    Posts:
    250
    hand-made is find :). I would need to look at/run the whole program, and the numbers being generated to work out what is happening. Also, I noticed in the video, the grid lines tend to break up and some disappear and reappear.