How can I match Unity's gravity implementation per object?

Hello,
I have a character that needs to change gravity and I’m trying to duplicate how Unity is applying gravity since the character has to use a consistent gravity speed as the other rigidbodies in the scene, but is not using the same direction.

In my rigidbody, I unchecked “Use Gravity” and in my code I added the line:

def FixedUpdate() {
    rigidbody.AddForce(gravity * gravityDirection.normalized);
}

where gravity is the same number as the one found in the Unity Physics settings (9.81). This makes the gravity a lot lighter than how Unity is applying it, though. I don’t know the exact number, but I played around with multiplying the gravity in code and it seems if I do:

rigidbody.AddForce(gravity * gravityDirection.normalized * 4.0);

it is closer to Unity’s gravity setting, but it’s still not exact.

How can I implement gravity in my FixedUpdate function so that it matches Unity’s internal rigidbody implementation exactly?

Unity’s implementation of gravity is pretty close to earths, at least at low speeds :slight_smile: This means that 9.81 N of force is added for every 1 kg of mass in the object.

Teasing aside here is an answer for you.

rigidbody.AddForce(gravity * gravityDirection.normalized * rigidbody.mass);

Googling classical or Newtonian physics will also help with the implementation. PhysX pretty much implements Newton and noting else.