Discussion I still can't understand the physics in Unity.

Discussion in 'Physics' started by EIVN, May 16, 2024.

1. EIVN

Joined:
Sep 18, 2022
Posts:
9
Hello. I've been working with Unity for about 2 years. I still can't understand the physics in Unity.

The main questions arise regarding the SI system. Meter, kilogram, etc.

What is 1 meter in units? What is 1 kg equal to? What is 1 newton equal to?

They say that Unity uses its own units. And this is extremely strange, since the whole world uses SI units.

Here's an example - a 2D platform game, like Mario.
My current task is to make the player move 1 meter in 1 second. I want to do the movement using rb.AddForce

I don't know what a meter is (in unity units).
I don’t know what 1 kg is equal to (in Unity, a solid has its own units)
I don’t know what the force is equal to (in units Newtons or its own units)

As a result of applying force to a rigid body, the player moves some distance.

Absolutely nothing is clear. And this is a primitive action.

In physics everything is fine - 1 kg, 1 newton, 1 meter - complete calculation, predictability. There are all the formulas, all the patterns for any task - sliding, rolling, drag, flight, lift, etc.

How do you generally work with this in Unity?

PS
I watched a bunch of videos on YouTube.
None have normal, basic movement using rb.AddForce. The authors of the video adjust the parameters of mass and strength to the desired result - a little faster or slower, by eye.

Where are the physics, calculations, formulas? Where is 5th grade physics?
What if you need more accurate calculations, more precise control of physics and interactions?

Unity Technologies

Joined:
May 24, 2013
Posts:
11,761
You mean Box2D or PhysX, there's nothing Unity specific about it.

In 2D (Box2D) everything is in MKS (Metres, Kilograms and Seconds).

1 Meter = 1 World Unit.

It's a Kg, I have no idea what you mean by "a solid has its own units". Mass is mass. It doesn't matter however, you could assume it's a unit of oranges, it doesn't make any real difference to stuff in Unity. The main thing is to not have huge mass ratios contacting each other i.e. a fly hitting a mountain.

The force is in Newtons but this Unity isn't really that relevant. The value you use will be time-integrated into velocity. If you add 10 onto X then the next simulation step 10 * deltaTime will be added to the velocity X. Simple.

The main reason MKS is used is that the physics engine is "tuned" around using reasonable values i.e. sizes from 0.1 to 10 meters (etc) although it's still happy with things much larger than that. Kilograms is used as a unit for the same reason so if you were to use nano-grams the values would be huge.

I'm not sure what's confusing about it specifically but again, it's not a Unity thing.

This could be you refering to lot of things. The main issue often encountered is scale i.e. the camera viewing a huge region and objects being tiny so needing to use huge forces. Remember if an object is moving at 330m/second then it's travelling at ths speed of sound. Just keep things reasonable. Maybe you mean that adding forces doesn't instantly change stuff but that's basic because it's modifying velocity i.e. speeding-up or slowing-down. You are free to directly modifying Velocity if you know what you're doing.

I really don't follow what you mean. It just sounds like you're misunderstanding a bunch of stuff and are indirectly asking for "more precision or control".

2D physics uses Box2D: https://github.com/erincatto/box2d/tree/main
Box2D Docs: https://box2d.org/documentation/index.html

arkano22, Ryiah and Edy like this.
3. Edy

Joined:
Jun 3, 2010
Posts:
2,565
In Unity all units are SI, unless mentioned otherwise (i.e. rpm in wheels, instead of rad/s). Distance is meters, mass is kg, force is Newtons, etc.

Physics in Unity work perfectly as expected and produce realistic results (within reasonable tolerances). If something doesn't work for you, then obviously you're doing something wrong, or haven't understood it right, or both.

Maybe you should start understanding physics. As a result of applying force to a rigidbody, the rigidbody receives some acceleration. As result of that acceleration, the velocity of the rigidbody increases. As result of that velocity, then the rigidbody moves some distance.

If you want a rigidbody to move 1 meter in 1 second you need the velocity of that rigidbody to be (surprisingly) 1 meter per second (1 m/s). If the rigidbody's mass in 1 kg, then applying a force of 1 N will produce an acceleration of 1 m/s/s (1 meter per second each second). After 1 second applying such force continuously, the velocity of the rigidbody will be 1 m/s (assuming there are no frictions, other forces, collisions, etc).

Alternatively to forces, Unity allows to apply impulses or direct velocity changes. With the parameter ForceMode.VelocityChange, AddForce may modify directly the velocity of a rigidbody by the given amount in a single call. So you may even bypass the acceleration stuff and ensure your rigidbody moves exactly at the velocity you want.

MelvMay and dstears like this.