RigidBody useGravity and box collider

Hello everybody,
I faced a problem with useGravity. I have a script attached to a 2D character and i want to control the gravity of this character. When I use GetComponent<Rigidbody>().useGravity = false;, I can control the gravity but i can’t add a 2d boxcollider.

What’s the equivalent of the code above using the 2d Rigidgoby ? like that i could add my 2d boxcollider. Thanks in advance.

Not tested but probably

GetComponent<Rigidbody2D>().gravityScale = 0;

Change the 0 to a higher number if you want to enable gravity.

It’s work fine. And I found also

, like that I can change the direction of gravity. Thanks

1 Like