gravity physics

Anyone knows what formula Unity uses for gravity?

To be more specific, I have a rigidbody on the floor. I want to rigidbody.AddForce(Vector3.up * 10);

Would that start moving the object immediately up?

I hope not, since if the object is heavy, you would need more force to lift it than if it is lighter.

Anyone knows what’s the break-even formula where if you apply X Vector3.up the object will not fall/lift?

Regards

I have a related question, but first let me respond.

In my example, if I did rigidbody.AddForce(Vector3.up), it did not have any effect. I imagine you need to do it every FixedUpdate to make it work (didn’t check that).

I noticed that if you set the parameter mode to ForceMode.Impulse, it will have the effect you describe.

The docs say this about the forces:

• ForceMode.Force : acceleration, depends on mass, call in FixedUpdate
• ForceMode.VelocityChange : changes the velocity, undependant of mass, doesn’t say if you call it once or have to keep calling it, but my bet is you call it only once
• ForceMode.Acceleration : same as force, but ignores mass
• ForceMode.Impulse : changes the velocity, depends on mass, I found out you should only call this once, otherwise your object will quite quickly reach absurd speeds

As for my related question, I couldn’t figure out how to change the fall speed of an rigidobject. I have drag = 0, gravity enabled so regardless of mass it should fall down with a 9.8 acceleration, but it just moves in slow motion.

You can use

``````Physics.gravity = new Vector3(0F, -12.0F, 0F);
``````

to change the gravity in the Game World.

My Objects also fall to slow but with more gravity it looks better.

If your objects are not to real-life scale, then the default gravity setting of -9.81 might seem slow. Try to keep everything to a reasonable scale or scale up the gravity value like biohazard mentioned. (You don’t want to go too off-scale though)

@biohazard_ffm and myraneal : thanks guys, I will scale it down first then see if I have to change the gravity value. I wasn’t even aware of this global Physics object, I really should do those tutorials soon

Oh BTW here’s a wip if your interested Unity Web Player - number3

Hi,

while we are still on the topic, I would like to have my objects in “real-life scale”. But what is the 1 unit in Unity equivalent to in real life? Is it 1 meter or something else?

thanks

Scroll down to “Use the right size” section.

Strictly speaking, you can use any scale you like. It’s just that the physics in Unity are intended to be in meters (for example, gravity defaults to -9.8 units/sec/sec).

Sorry if i’m hijacking the thread but would this be a start off point to create, let’s say, Mario galaxy kind of gameplay?

Changing the Physics.gravity property dynamically would be one way, but there are others as well (roll-your-own gravity) that would likely work better, like having objects attract to a point rather than a global direction.

If you do a search of the forums there are loads of old threads about this. There are some scripts on the wiki, and podperson had posted some really good scripts for that type of thing as well. I even posted one myself, which is here.

If you want to implement your own gravity separate from that of the rest of the physics engine, remember that

F=MA

Gravity (usually -9.81) is an acceleration, it is constant for all objects regardless of mass. What you want to do is apply a force dependent on the mass so that it will appear constant.

therefore, ForceApplied = Mass X The desired Accelleration

rigidbody.AddForce( 0, rigidbody.mass * -9.81, 0 );

this would make the object move at a constant acceleration of -9.81 meters per second squared, and so you would not need to worry about the rigidbody’s mass.

Apologies for the dissertation to follow, just having worked on this type of thing myself I just had to get a word in. :lol:

Well, that’s really just a specific case for calculating accelleration due to gravity as it affects objects very close to a body with a very large mass (like a planet). The ‘little g’ gravity formula:

F = m*g

is just a simplified form of the ‘big G’ formula:

F = G * (m1 * m2) / r^2

The reason acceleration due to gravity appears constant in the context of objects falling to earth is because the effect of two parts of the full equation, the mass of the object falling and the distance from the earth, are assumed to be negligible compared to the mass of the earth. They do exert an equal and opposite force on the earth, but since because they’re so small relative to the earth you can safely call the acceleration of the earth towards a feather or a bowling ball nil.

I’m oversimplifying a bit, but basically if you’re talking about simulating gravity ‘in space’ between different objects it can be more useful to use the expanded formula if only because it lets you account for distance.

Although I guess if you want to do a Super Mario Galaxy kind of thing it would probably be simpler to set up triggers around each planet or asteroid and then just have the player switch to ‘local gravity’ for each object as they trigger them (less potential of flying off into space or unintentionally going into orbit, for one thing).

And G = 6.67e-27

To this day I have no idea why I memorized the value for the gravitational constant ever since I learned it in my high school physics class over 30 years ago.

I thought it was 6.67 X 10^-11…

No wonder I failed in physics.

3 Likes