how can i use multiple gravity direction in multiple game objects?

I’m new to unity. I have 2 game objects. First one should have a gravity towards the negative Y direction and the Second game object should have gravity towards negative Z direction.

Physics.gravity = new Vector3(0, -9.81f, 0);

Physics.gravity = new Vector3(0, 0, 9.81f);

I have following 2 code for these 2 game objects. But if the first one is going towards negative Y direction then second one is also going to the negative Y direction instead of going towards the negative Z direction.

Please help me… Thanks in advance…

If you don’t want to bother with calling AddForce each frame, there is the ConstantForce component ! :wink:

Rigidbody.AddForce applies a force to the Rigidbody only for one frame, thus you have to keep calling the function. ConstantForce on the other hand will apply the force every frame until you change the force or torque to a new value.

Physics.gravity is a global parameter that affects all your objects in your scene. You cannot have different gravities for each object. In your code, the second line overwrites the first one.

You should set the gravity to zero and set a different Rigidbody.AddForce to each object to simulate gravity.