Change direction of gravity for a specific instance of a prefab


I’m very new to unity and scripting in general. What I’m trying to do is create a puzzle game where in certain levels gravity is of a different direction that other objects.

See the following Diagram




B1, B2, B3, and B4 are all instances of prefab B. Block is just a stationary Block. B1-3 I would like to have normal gravity, but B4 I would like to have inverted gravity. Obviously the levels will be more complex with gravity going along both axis’ for different objects, etc.

What I tried to do was this in update:

if(rigidbody.mass == 3.1313)

gravity = new Vector3(1f,9.81f,0f);


I thought if I changed the mass ever so slightly on those instances, and used that as a unique attribute, it would allow me to change the gravity. This did not work lol. Any help would be greatly appreciated!

You can’t do this simply with the gravity. However, you could simulate the gravity for all your objects by adding a constant force. Those with the regular gravity will have the constant force at (0,-9.81,0), and you can change the other as you like. Just don’t forget to disabled ‘useGravity’ on every rigidbodies.