Unity Development — Introduction to Physics

Siddhant Thakur
5 min readMar 26, 2021

Unity helps you simulate Physics with the help of it’s built-in Physics Engine, this is done to ensure that your game objects correctly respond various kinds of forces in the game be it Gravity, Acceleration,Collisions, etc.

Rigidbody :

Rigidbody’s are components that allow game objects to be affected by Physics.

We can observe that the sphere game object without the Rigidbody component stayed static in the air whereas once the component was added it got affected by gravity and well… fell.

Let’s add an obstruction in the path of the sphere and observe how it reacts.

Here it can be observed that the sphere behaves the way it’s supposed to and interacts with the cube object that has no rigidbody. With this we know that not only does rigidbody allows game objects to be affected by forces, but also allow objects to have interactions with any object that has any sort of collider attached to it.

Rigidbody has the following properties,

Let’s start of with the Use Gravity checkbox, enabling this is what allows our sphere object to experience the force of gravity(making it inevitably fall down).

Here we can observe what happens when we toggle Use Gravity

Mass, as the name suggests is the mass of our game object in Kilograms. Let’s give the cube a rigidbody and toggle Use Gravity off to show how Mass effects the game objects.

Both Objects have the same Mass
Cube with a Mass of 100

Drag, think of this as friction that is applied on the object due to the air/water surrounding it. It generates an opposing force. When the linear drag is 0(default value), implying that from the game object’s perspective, the world around it has no friction so unless we stop the object, it will continue to move infinitely.

No Linear Drag
Linear Drag set to two

Angular Drag, this is essentially linear drag but it affects the rotation of the object. Lets take an example to show this, both the objects in the scene have the same Mass.

Angular Drag of Zero
Angular Drag of Hundred

Is Kinematic checkbox, when enabled the object will no longer be under the effect of Unity’s Physics Engine and can only be manipulated using it’s transform.

First let’s add a Movement script to your cube which will move it to the right.

Here _speed is a Serialized Variable

The main purpose for toggling “Is Kinematic” to true is to control the movement of the object through either the animator or the transform. Now the question arises as to why we need to use a Kinematic Rigidbody over a static object which is nothing but an object with a collider but with no Rigidbody.

When an object with a Rigidbody component moves, Unity expects it to move as they are a part of the Physics system. But when a Static object(without a Rigidbody) which is always assumed to be static by Unity’s Physics engine moves, it requires the engine to re-run calculations every time the static object moves(basically rebaking) as from Unity’s perspective the World has changed. But when we add a Rigidbody, it is saying that this object is interactive so try not to do any of the optimizations the physics engines uses for static world objects, and when we tell the engine that this object is Kinematic it technically means the same just that the controls are now in the hand of your Scripts and the Animator.

Interpolate, this contains three options Interpolate, Extrapolate, None. The default is None and needs to remain None unless you see jitters or jerkiness in your Rigidbody’s movements.

Interpolate : This deals with smoothening the transform based on the previous frames.
Extrapolate : This deals with smoothening the estimated transform based on the next frame.
None : This deals with applying no Interpolation/Exterpolation.

Collision Detection are of 4 types
Discrete : This type of collision is used for normal collisions, and this is also the least intensive collision detection method so unless you’re dealing with really fast moving objects I’d suggest you stick with this.
Continuous : This type of collision is mainly used when dealing with fast moving objects.
Continuous Dynamic : This type of collision is used when dealing with fast moving objects and when both the objects have a Rigidbody. But this is very resource intensive.
Continuous Speculative : This type of collision does what continuous and continuous dynamic does but it does it better, faster and is comparatively less resource intensive, but comes at a cost of accuracy.

Constraints, This restricts the Rigidbody’s motion along it’s respective axises. For example,

No Constraints
Constraining the Y-axis on the position constraint
Constraining the Y-axis on the Position Constraint and Z-axis on the Rotation Constraint

Note: Here the cube has a mass of 0 whereas the sphere has a mass of 100. Which is why it gives us an illusion of the sphere passing through the cube, below is the same implementation as above where both have a mass of 100.

Mass of 100 kgs

Info, Lastly Info this contains all your information regarding your Rigidbody. You can monitor it at real time to check how it’s doing.

This was a basic overview of how physics works in Unity.

--

--

Siddhant Thakur

Aspiring Game Developer with experience in the field of Machine Learning.