- Home /
Rigidbody2D Individual Gravity
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 **Rigidbody2D**s 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 );
}
Answer by JediMan · Jun 03, 2019 at 11:55 AM
f I understood the question correctly, then, maybe, you can make the the object named "isGround" and check whether this object is in collision with objects taged "ground". And if your objects isn't in collision with ground, you can just reduce Y coordinate from the object until it will be "grounded".
You misunderstood my question. What I wanted to know is how do I able to achieve for each rigibody is able to have its own unique gravity with directions. I noticed that modifying global physics would not help because it affects the world ins$$anonymous$$d of individual gameobject.
Your answer
Follow this Question
Related Questions
,My Character is falling through my Tilemap 0 Answers
Error when colliding and calling a IEnumerator 1 Answer
Jumping and reverse gravity with a Rigidbody2D (based on the Ruby tutorials) 1 Answer
How do I make a rigidbody2d that doesn't do anything on collision? 1 Answer
Player slides down slope. 0 Answers