I am trying to have individual gravity for each rigidbody2D( Circle Collider 2D with gravity scale = 0 ) in the game. So I had tried to use “Rigidbody2D.AddForce” and “ConstantForce”, but it did not turn out the way that I wanted and some weird collisions happened.
Sometimes, the Rigidbody2Ds will overlap each other and keep spinning around even though not moving. And also, a very rare occasion one of the Rigibody2Ds that is not moving will suddenly have some sort of “Impulse” force added to it and bounce off even though no such logic is coded. The Rigidbody2Ds also keep pushing one another when they stick too close with each other ( I think its caused by the constantly AddForce, but tried to check velocity but did not work as well ).
I am looking for advice in order to code Individual Gravity properly for 2D game. Any help or advice are much appreciated.
I wonder constantly adding force in FixedUpdate is it bad for performance even though I am trying to code custom gravity.
Hope the information below is able to help.
private void FixedUpdate()
{
this.rigidbody2D.AddForce( gravityDirection.normalized * 9.81f );
}