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.
if (aBubbleNumber == (short)(cCellSlotIndex / EntityManager.PIECE_COUNT))// when cells are siblings
{
if (aCellModel.qCellCoolDown < 0.0f && cCellModel.qCellCoolDown < 0.0f)// when one cell can consum the other cell
{
if (aCellModel.mCellMass > cCellModel.mCellMass)
{
if ((aCellModel.mCellLocalPosition - cCellModel.mCellLocalPosition).sqrMagnitude < aCellModel.nCellRadiusSquared)
{
cCellModel.Change_CellActive(false);
aCellModel.Change_CellMass(aCellModel.mCellMass + cCellModel.mCellMass);
}
}
}
else// when one cell can not consum the other cell, they should be pushed each other
{
float distance = (aCellModel.mCellLocalPosition - cCellModel.mCellLocalPosition).magnitude;
if (distance >= aCellModel.nCellRadius + cCellModel.nCellRadius) continue;
float magnitude = (aCellModel.nCellRadius + cCellModel.nCellRadius - distance) / (aCellModel.mCellMass + cCellModel.mCellMass) * cCellModel.mCellMass;
Vector2 displacement = Vector2.ClampMagnitude((aCellModel.mCellLocalPosition - cCellModel.mCellLocalPosition), magnitude);
aCellModel.Change_CellLocalPosition(aCellModel.mCellLocalPosition + displacement);
}
}
https://drive.google.com/file/d/1VPCDg0_dn0oeTdAtLPi3BcZodxob7CgQ/view?usp=sharing