- Home /
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?
Answer by Kiwasi · Dec 13, 2014 at 02:37 AM
Unity's implementation of gravity is pretty close to earths, at least at low speeds :) 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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613173915im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make rigidbodies on each side of a cube fall towards the cube? [multiple gravity / addForce] 0 Answers
Setting a RigidBody's velocity messes with my custom gravity, not sure how to proceed. 0 Answers
Gravitational pull without losing speed 1 Answer
Rigidbody (with Box Collider) falls through floor 1 Answer
How to re-center a Rigidbody isKinematic object after adding force to it? 2 Answers