What is a RigidBody in Unity?

By GameDevTraum

Introduction

In this article we are going to see the RigidBody component in Unity, what it is for and how to use it.

Knowing about this component will allow you to create precise physics in your game.

What is a RigidBody in Unity?

First RigidBody in Unity is a “Programming Class” defined at the core of the engine and accessible via Script using the namespace “UnityEngine”. This in simple terms means that it is a programming structure that seeks to model a particular type of behavior. Here you can see an introduction to classes in programming.

RigidBody means Rigid Body, which in the study of physics is a way of thinking about certain objects and being able to make calculations and predictions in different scenarios.

The RigidBody class models the concept of Rigid Body in physics and allows us to treat GameObjects as if they were physical objects that have their own mass, are affected by gravity, can collide with other objects, exert forces on other bodies, have a coefficient of friction depending on the surface they are on, have linear and angular velocity, inertia, angular momentum.

To these bodies we can apply forces or torques and these Rigid Bodies will respond based on the classical equations of Newtonian physics. Beautiful!

To learn more about what a GameObject is in Unity, visit this article.

Rigidbody Component in Unity

In the Unity hierarchy we have the list of GameObjects that are in the scene. If we choose one of them, we will be able to see its components in the inspector and add the ones we need to model its behavior. Here we can add to the GameObject the RigidBody component that will provide the physical Rigid Body behavior.

Colliders and RigidBody

Colliders are fundamental to being able to use a GameObject as a Rigid Body, as they provide the GameObject with a border to determine when it collides with other objects.

In the following video you can see different types of Colliders and in the final part how it relates to the RigidBody component. English Subtitles available.

Apply forces to a RigidBody in Unity

Some time ago I did a series of basic tutorials for Unity in which I showed how to use basic engine components and methods. In one of them I showed how to apply forces to RigidBodies. You can see it below, english subtitles available.

Because RigidBody is a class, it has a variety of public methods that allow you to access your internal state or perform certain functions. Among them is the possibility to apply a certain force to the GameObject.

Conclusion

RigidBody is a Programming Class defined in the engine core, accessible by the namespace UnityEngine. This class allows us to give GameObjects the behavior of physical Rigid Bodies with all that entails.

Colliders are essential to delimit the Rigid Body border and to calculate forces and collisions with other GameObjects with RigidBody.

Using the public methods of the RigidBody Class we will be able to apply forces, linear and angular velocities, torque and modify a great variety of properties present in the study of Newtonian physics.