Different gravity for different bodies. (2D game)

Some time ago while I was developing a top-down 2D minigolf game, I needed to implement some ramps.

In order to simulate planar physics(not sure if is the correct name), I had the global gravity set to zero, when a body was inside the ramp boundaries, I changed the gravity for that body according to the slope of the ramp. So, for instance, I could have simultaneously a body moving down the ramp while another body was moving over a flat section.

In order to do that I had to modify a couple of lines of the box2d code. I was wondering if this can be achieved in Unity, given that you can’t modify the physics engine.

Just as reference, in the Bullet engine, as far as I know, this is a native feature: btRigidbody::setGravity()

Sorry for my English, I hope the question is clear.

what you need is precisely the ConstantForce component.

that is exactly how you “modify” gravity on a SPECIFIC object.

you definitely should not modify the overall gravity setting in Unity. it will lead to vast complications.

you can also simply TURN OFF gravity on an object (look at the rigidbody inspector) at timed when you don’t want gravity.

Try disable “Use gravity” in Rigidbody options and change velocity from FixedUpdate with AddForce (its may lead problem with sleeping, but i’m not sure).