To have convincing physical behaviour a game object must
accelerate correctly, have a feeling of proper mass
and be affected by collisions, gravity and other
forces in a realistic way.
Unity's built-in physics engines provide components
that handle these physical simulations.
There are two separate physics engines in Unity.
One for 2D physics and one for 2D physics.
The main concepts are identical between these two
physics engines, except for the extra
third dimension in 3D physics.
These systems are implemented however with
completely different components.
When using 2D physics the physic 2D components
will seem familiar to those who have used the 3D physics engine.
Most of the physics 2D components
behave in a similar way to their 3D counterparts.
Except in 2 dimensions.
And have similar names, except with 2D after
the descriptive part of the name.
For example, in 3D physics
there is a rigidbody component.
In 2D physics there is analogous
rigidbody 2D component.
This pattern will hold true for most of the physics
2D components and scripting methods.
Including box collider and box collider 2D.
Or OnTriggerEnter and OnTriggerEnter2D.
It is important to note that these 2 physics systems
are comparable but not compatible.
3D physics and 2D physics can be present
in the same scene, but they will not interact with each other.
There are some important differences between
2D physics and 3D physics.
The most critical difference is that there is no
concept of depth in 2D physics.
All 2D physics plays out on the X/Y plane
with this 2D plane at 0 along the Z axis.
Game object under control of the 2D physics engine
can only move on an X/Y plane
and can only rotate around the Z axis.
As it is possible to view a 2D game
when the editor is in 3D mode
and it is possible to change the transform
position Z of a game object
that is using 2D physics
it is important to remember that all of the
physics interaction takes place at the
Z axis position of 0.
2D physics has a number of project-wide settings.
These can be edited by selecting
Edit - Project Settings - Physics 2D.
These settings contain details on the
properties like strength and direction of gravity,
the default material and the layer collision matrix, and more.
For more information on the physics 2D settings
please see the information linked below.
One of the primary components used in physics 2D
is the rigidbody 2D.
Attaching a rigidbody 2D component
places a game object under the control
of the 2D physics engine.
The rigidbody 2D component works with colliders
to detect collisions, can receive forces and torque
operate various types of joints
and other specialised 2D physics behaviour.
This component is also used to keep track
of important physical properties about the game
object the component is attached to.
It has properties for the object's mass
linear and angular drag, gravity scale and many others.
For more information on the rigidbody 2D component
please see the information linked below.
Every 2D project has a default value in the
physics 2D setting for Gravity.
Gravity will effect all game objects with a rigidbody,
unless that rigidbody is set to ignore gravity.
This is done by setting the gravity scale to 0.
Any other value for gravity scale
will be used to modify the default value
for gravity, and this can be done on a
game object per game object basis.
If the game object has a collider 2D attached
it can participate in physical collisions or trigger events.
2D colliders allow game objects to have
physical shape, or presence, in the scene's 2D environment.
There are several types of 2D colliders
that work with a rigidbody 2D.
The circle, the box, the edge and the polygon collider.
Each collider type has a different set of behaviours
and can be used in different circumstances.
For more information on the collider 2D component
please see the information linked below.
When a game object has a rigidbody 2D attached
it can use one of the several joint 2D components available.
When using a joint 2D component
the game object can participate in complex and
specialised physical behaviour, like hinges,
springs, sliders and couplings.
2D joints allow a game object to be
anchored to either a point in the scene
or another game object,
and react physically to that anchor.
In some cases several game objects
with a joint 2D can be attached to each other
for more interesting and complex behaviours like chains.
For more information on the joint 2D components
and how to use them,
please see the information linked below.
The surface properties of a collider 2D are
defined by a special type of material.
This material is the physics material 2D asset.
A physics material 3D is used to control the
friction and bounce that occurs between 2 game objects
with collider 2D components attached when they collider.
To make a bouncing ball, or slippery ice covered
use a different physics material 2D
on each game object.
For more information on material assets
and physics materials please see the information linked below.
Subtitles by the Amara.org community