Unity’s Physics engine allows developers to work in an environment that closely approximates the fundamental forces of the real world. Forces like gravity, velocity and acceleration are are all covered by Unity. Let’s take a look and see how this is implemented.
The collider’s main purpose is to provide information on when game objects collide or intersect each other. Unity provides functionality for 2D as well as 3D. The main difference between the colliders are the shape of them as the rest of the component options are pretty much the same.
In the inspector, you can edit the bounds of the collider, change its center and size and check if it is a trigger or not.
The trigger setting determines if the collider will be involved in the physics calculations from Unity.
Physic materials can be created in the project view and then applied to a collider. They all control the friction interaction of two rigid bodies and can be made to support a wide variety of friction types.
This controls the slow down friction when the of a collider-rigidbody than is moving.
Controls the “stuck in place” friction of a collider-rigidbody.
This is self-explanatory but it’s good to know how it’s implemented. A “0" value is no bounciness at all, where as a “1” value is pure bounce with no loss of energy.
This property determines how the friction of the colliding objects is combined. Unity provides four options for this. Average, minimum, maximum and multiply.
This operates virtually the same as the Friction Combine but with bounce instead.
The Rigidbody component is the main component of the physics system. Through code, you can manipulate the position and rotation of a rigid body by adding a force, torque etc. You can set properties like mass and drag, and whether or not you want it to be affected by gravity.
Checking “is Kinematic” will allow the rigid body to no be affected by physics, but can still affect others. You can also set the interpolation which will smooth out the physics simulation while it’s been used alongside the animation system.
If the “interpolate” option is set to “interpolate” it will use the previous animation frame to help smooth out the movement. choosing “extrapolate”, will use a “best guess” of the next frame for movement smoothing.
The collision detection setting will provide options on the rate of collision detection. “Discrete” is the default setting. “Continuous” is used for objects that are moving fast that will most likely be hitting static objects. “Continuous Dynamic” is used for fast objects hitting fast objects and “Continuous Speculative” uses a predictive collision system.
The “Constraints option” lets you set limits on how the rigidbody’s position and rotation can be affected.
That’s a basic overview of the main components of the physics system In Unity. There are more components that play a role such as Physics Joints and Ray Casting but those are topics for another article.
Thanks for reading,