Unity Physics: Rigidbody Basics

Jared Amlin
Nerd For Tech

--

Hello game lovers! In this next series, I will cover a variety of topics having to do with using Unity’s physics engine. Let’s start at the beginning, with Rigidbodies and hard-surface collisions.

In order for any collision to happen in Unity engine, both objects need to have a collider, and at least one of the objects needs a Rigidbody component.

Rigidbody

The Rigidbody component houses variables for the basis of physics based behaviors.

Mass: Here is the description of mass directly from the Unity documentation.

The mass of the rigidbody. Different Rigidbodies with large differences in mass can make the physics simulation unstable.

Higher mass objects push lower mass objects more when colliding. Think of a big truck, hitting a small car.

A common mistake is to assume that heavy objects fall faster than light ones. This is not true as the speed is dependent on gravity and drag.

Drag: Per the Unity documentation.

Drag can be used to slow down an object. The higher the drag the more the object slows down.

Here is a more involved physics definition of drag, completely outside of Unity engine.

“In fluid dynamics, drag, sometimes referred to as fluid resistance, is a force acting opposite to the relative motion of any object, moving with respect to a surrounding fluid. This can exist between two fluid layers, two solid surfaces, or between a fluid and solid surface. Drag forces tend to decrease fluid velocity relative to the solid object in the fluid’s path.

Unlike other resistive forces, drag force depends on velocity. This is because drag force is proportional to the velocity of low-speed flow, and the squared velocity for high-speed flow. This distinction between low and high-speed flow is measured by the Reynolds number.”

Imagine an airplane lifting it’s flaps to create drag and slow the craft in preparation for landing

Angular Drag: Similar to drag impacting movement speed, angular drag can be used to slow down the rotation of an object. The higher the drag the more the rotation slows down.

Automatic Center of Mass: Determines whether or not to calculate the center of mass automatically.

Automatic Tensor: Determines whether or not to calculate the inertia tensor automatically. If enabled, the inertia tensor is calculated automatically based on the settings of attached Colliders. If no colliders are present, the tensor has a default value of Vector3(1,1,1).

Use Gravity: This arguably the most essential part of a physics simulation in Unity. When enabled, the object uses Unity’s physics engine to apply gravity force.

Is Kinematic: Enabling this setting let’s an object use a rigidbody, while ignoring the expected gravity, forces and collisions that come with typical physics based behaviors. Here is a thorough description, taken straight from the Unity documentation.

If isKinematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore. The rigidbody will be under full control of animation or script control by changing transform.position. Kinematic bodies also affect the motion of other rigidbodies through collisions or joints. Eg. can connect a kinematic rigidbody to a normal rigidbody with a joint and the rigidbody will be constrained with the motion of the kinematic body. Kinematic rigidbodies are also particularly useful for making characters which are normally driven by an animation, but on certain events can be quickly turned into a ragdoll by setting isKinematic to false.

Interpolate: Because rigidbody movement runs best in fixed update, movement can sometimes appear jittery due to physics updates.

Interpolation provides a way to manage the appearance of jitter in the movement of your Rigidbody GameObjects at run time.

Interpolation calculates the pose of a Rigidbody in frames that fall between physics timestep updates, to reduce the appearance of visible jitter.

Collision Detection: Discrete collision should be active by default. If fast moving objects have issues moving through colliders unexpectedly, you can set them their collision detection to Continuous Dynamic. The objects being hit with other fast moving objects, can have their collision detection set to Continuous. These settings however, will have an impact on physics performance. A performant alternative that can be used on kinematic rigidbodies, is Continuous Speculative.

Constraints: You can use constraints to ignore expected positional or rotation changes when encountering physics behaviors and collisions. If you have a player capsule that uses rigidbody physics for movement, you can use the appropriate constraints to keep it from falling over when you start the game.

Layer Overrides: You can use the inspector to control collision layers for your rigidbody. Collision layers can be used to determine which objects are allowed to collide with other objects.

Colliders

While only one object needs a rigidbody for a collision to occur, every object needs a collider. Unity has a lot of 2D and 3D collider options for you to explore, but the most frequently used of them is arguably the Box Collider. Without diving deep into the various collider types and all of their features, I will just mention the Is Trigger tick-box here. When this is enabled, your collider will be setup for pass-through collisions. For realistic physics based collisions, that box needs to be un-checked, which results in hard-surface collisions.

That’s it for this introduction to physics in Unity Engine. I hope to see you here for my next article, and thanks for reading!

--

--

Jared Amlin
Nerd For Tech

I am an artist and musician, that is currently diving headfirst into game development with C# and Unity3D.