In this lesson, you will learn how to use Angular Drag and Rigidbody constraints to keep your character upright and prevent them from tumbling over like a bowling pin when they collide with objects.
The Problem with Physics Rotation
When you apply force to a character using a Rigidbody, the physics engine treats that character like any other object. If your player walks into a wall or gets bumped by a crate, the force of that collision often creates "torque," causing your character to tip, spin, or fall over. In most platformers or action games, this is undesirable—we want our character to remain oriented vertically while moving.
Taming Rotation with Angular Drag
The Rigidbody component has a property called Angular Drag. While standard "Drag" slows down movement, "Angular Drag" specifically resists rotation. By increasing this value (try setting it to 10 or higher), you make it much "heavier" for the physics engine to rotate your character. It acts as a dampener that absorbs the energy from collisions, keeping your character from spinning out of control.
Locking Axes with Constraints
If increasing Angular Drag isn't enough, or if you want to ensure your character never tips over, you can use Rigidbody Constraints.
Inside the Rigidbody component, find the Constraints foldout. Here, you can check the boxes for Freeze Rotation X and Freeze Rotation Z. This tells the physics engine to ignore any rotational forces applied to those axes. Your character will still move through the world, but it will be physically locked to remain upright.
You can also set these via script if you need to toggle them dynamically:
void Start()
{
Rigidbody rb = GetComponent<Rigidbody>();
// Freeze rotation on X and Z axes to keep the character upright
rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
}
By combining higher Angular Drag to dampen erratic movement and Constraints to lock critical axes, you gain total control over your character's balance.
Key Takeaway: Use Angular Drag to dampen unintentional rotations and Rigidbody Constraints to force your character to stay upright regardless of collision forces.