An Introduction To 3D Physics In Unity

Adam Reed
3 min readMar 30, 2021

--

Unity has a built-in physics system that is ready and easy to use! It’s as simple as adding a “Rigidbody” component to a gameobject. By doing this, you will put the gameobject’s motion under the control of Unity’s physics engine.

[Note]

It is highly recommended that you apply forces and change the Rigidbody settings in the FixedUpdate function(as opposed to Update, which is used for most other frame update tasks). The reason for this is that physics updates are carried out in measured time steps that don’t coincide with the frame update. FixedUpdate is called immediately before each physics update and so any changes made there will be processed directly.

Within the RigidBody component, you will find a list of properties that you can adjust. These will allow you to customize how Unity’s built-in physics will respond to this object. The definitions of each of these are listed below.

Properties Defined

Mass — The mass of the object (in kilograms by default).

Drag — How much air resistance affects the object when moving from forces. 0 means no air resistance, and infinity makes the object stop moving immediately.

Angular Drag — How much air resistance affects the object when rotating from torque. 0 means no air resistance. Note that you cannot make the object stop rotating just by setting its Angular Drag to infinity.

Use Gravity — If enabled, the object is affected by gravity.

Is Kinematic — If enabled, the object will not be driven by the physics engine, and can only be manipulated by its Transform. This is useful for moving platforms or if you want to animate a Rigidbody that has a HingeJoint attached.

Interpolate — Try one of the options only if you are seeing jerkiness in your Rigidbody’s movement.

  • None — No Interpolation is applied.
  • Interpolate — Transform is smoothed based on the Transform of the previous frame.
  • Extrapolate — Transform is smoothed based on the estimated Transform of the next frame.

Collision Detection — Used to prevent fast-moving objects from passing through other objects without detecting collisions.

  • Discrete — Use discrete collision detection against all other Colliders in the Scene. Other colliders will use discrete collision detection when testing for collision against it. Used for normal collisions (This is the default value).
  • Continuous — Use Discrete collision detection against dynamic Colliders (with a Rigidbody) and sweep-based continuous collision detection against static Colliders (without a Rigidbody). Rigidbodies set to Continuous Dynamic will use continuous collision detection when testing for collision against this rigidbody. Other rigidbodies will use Discrete Collision detection. Used for objects with which the Continuous Dynamic detection needs to collide with. (This has a big impact on physics performance, leave it set to Discrete, if you don’t have issues with collisions of fast objects)
  • Continuous Dynamic — Use sweep-based continuous collision detection against GameOjects set to Continuous and Continuous Dynamic collision. It will also use continuous collision detection against static Colliders (without a Rigidbody). For all other colliders, it uses discrete collision detection. Used for fast-moving objects.
  • Continuous Speculative — Use speculative continuous collision detection against Rigidbodies and Colliders. This is also the only CCD mode that you can set kinematic bodies. This method tends to be less expensive than sweep-based continuous collision detection.

Constraints — Restrictions on the Rigidbody’s motion:

  • Freeze Position — Stops the Rigidbody moving in the world X, Y, and Z axes selectively.
  • Freeze Rotation — Stops the Rigidbody rotating around the local X, Y, and Z axes selectively.

--

--

Adam Reed

Hi, my name is Adam Reed and I am a software engineer specializing in Unity and C# development. Feel free to scroll through and check out some of my work!