Rigidbody Mass in Unity

by Vinod Ravisankar Published December 27, 2023

Introduction

Understanding the concept of mass in Unity’s Rigidbody component is essential for creating realistic physics simulation in a Unity game. In this article, we will discuss the role of mass in Rigidbody physics, specifically its impact on collisions and gravity, and how to manipulate it in the Unity Inspector and through scripting.

This is a series on Unity Physics. We recommend reading the series in order.

  1. Unity Physics
  2. Unity Collision Detection
  3. Character Controller and Input Systems
  4. Rigidbody Mass in Unity
  5. How to add Friction to a Rigidbody
  6. Cylinder Collider in Unity
  7. Box Collider in Unity
  8. Box Cast in Unity
  9. Sorting Layers
  10. Get the distance between two objects
  11. How to normalize a vector

What is Mass?

In Unity, mass is a property of the Rigidbody component, representing how heavy an object is. It influences how the object interacts with forces and other physics objects in the game world. The higher the mass, the more force it takes to move the object.

Mass of a Rigidbody is a floating point and can be set to any value either using the Unity’s inspector or using script. Just keep in mind that large variations in Rigidbody mass between multiple objects in a scene can make the physics simulation unstable.

Mass and Rigidbody Behavior in Collisions

In a collision, the mass of an object often gives the same outcome as in the real world. An object with a higher mass will exert a greater force upon collision, making it less prone to changes in its motion. This is important in games where realistic physics interactions are required. For instance, a bowling ball (mass value of 20) will push a tennis ball (mass value of 5) far away upon collision due to its greater mass.

Mass and Rigidbody Behavior with Gravity

In contrast to common assumptions, mass does not affect how gravity influences a Rigidbody in Unity. All gameobjects, regardless of their mass, fall at the same rate if only gravity is acting on it.The acceleration due to gravity remains constant and is not affected by the mass of the object.

This means a feather and a hammer will fall at the same rate in a vacuum. However, the motion is affected by other Rigidbody parameters like drag.

Changing a Rigidbody’s Mass in the Inspector

To adjust an object’s mass in Unity, select the object in the Hierarchy window, go to the Inspector window, and find the Rigidbody component. Here, you’ll find the ‘Mass’ property, which can be modified to your desired value. This is a straightforward method for changing the value of mass during the game development process.

Changing a Rigidbody’s Mass Using Scripting

If mass needs to be updated during runtime, then it can be altered via a simple script. This allows for real-time changes in mass based on game mechanics or player actions.

As in case of other components in Unity, the Rigidbody component needs to be accessed using GetComponent<> before assigning the mass.

Here’s a basic C# script to change a Rigidbody’s mass

using UnityEngine;

public class RigidbodyMassController : MonoBehaviour
{
  private Rigidbody rb;
  
  void Start()
  {
    rb = GetComponent<Rigidbody>();
    UpdateMass(5.0f);
  }

  public void UpdateMass(float newMass)
  {
    rb.mass = newMass;
  }
}

Conclusion

Mastering the concept of mass in Rigidbody components is critical for creating realistic physics in Unity games. Without the right understanding, a Rigidbody might end up not moving just because the mass was too high for the force applied.

Whether through the Inspector or scripting, understanding and manipulating mass can lead to more dynamic physics game environments.

Free download: Indie Game Marketing Checklist

Download now

Category

c sharp

Don't forget to share this post!

Popular assets for Unity

See all assets ->
    Cutting-edge volumetric fog and volumetric lighting with support for transparent materials.
    Volumetric clouds, day night cycles, dynamic skies, global lighting, weather effects, and planets and moons.
    A lightweight procedural skybox ideal for semi-stylized projects.
    Image-based Outlines for 2D and 3D games with variable line weight, color, and displacement options.
    Drag-and-drop ready-to-use ambient, impact, and spell particle effects.
    Per-pixel gaussian blur on your entire screen, part of the UI, or in-scene objects.

Free Indie Game Marketing Checklist

Learn how to make your game successful with this handy checklist.

Download for free