Version: 2022.3
物理 (Physics)

Physics 2D

Go to Edit > Project Settings… > Physics 2D to manage the global settings for Physics 2D.

Note: To manage the global settings for 3D physics, refer to the Physics Project settings documentation instead.

Physics 2D Inspector 设置
Physics 2D Inspector 设置

The Physics 2D settings define limits on the accuracy of the physics simulation. A more accurate simulation requires more processing overhead, and these settings allow you to adjust the trade off between accuracy and performance that best suits your project. Refer to the general Physics documentation for further information.

General Settings tab

The following are the properties available in the General Settings tab of the Physics 2D manager window.

属性 功能
Gravity 设置应用于所有 2D 刚体游戏对象的重力大小。通常,仅为 y 轴的负方向设置重力。
Default Material 设置在没有为单独 2D 碰撞体分配材质的情况下需要使用的 2D 物理材质
Velocity Iterations 设置物理引擎为处理速度影响而进行的迭代次数。数字越大,物理计算越准确,但代价是 CPU 时间增加。
Position Iterations 设置物理引擎为处理位置变化而进行的迭代次数。数字越大,物理计算越准确,但代价是 CPU 时间增加。
Velocity Threshold 设置弹性碰撞的阈值。Unity 将相对速度低于此值的碰撞视为非弹性碰撞(即,碰撞的游戏对象不会相互反弹)。
Max Linear Correction 设置解算约束时使用的最大线性位置校正(范围从 0.0001 到 1000000)。这有助于防止过冲。
Max Angular Correction 设置解算约束时使用的最大角度校正(范围从 0.0001 到 1000000)。这有助于防止过冲。
Max Translation Speed 设置任何物理更新期间 2D 刚体游戏对象的最大线性速度。
Max Rotation Speed 设置任何物理更新期间 2D 刚体游戏对象的最大旋转速度。
Baumgarte Scale 设置用于确定 Unity 解算碰撞重叠速度的缩放因子。
Baumgarte Time of Impact Scale 设置用于确定 Unity 解算撞击时间重叠速度的缩放因子。
Time to Sleep Set the time (in seconds) that must pass after a Rigidbody 2D stops moving before it goes to sleep.
Linear Sleep Tolerance Set the linear speed below which a Rigidbody 2D goes to sleep after the Time to Sleep elapses.
Angular Sleep Tolerance Set the rotational speed below which a Rigidbody 2D goes to sleep after Time to Sleep elapses.
Default Contact Offset Set a proximity distance value for Colliders to be considered in contact, even though they are not actually in contact. Colliders whose distance is less than the sum of their contactOffset values generate contacts. This allows the collision detection system to predictively enforce the contact constraint even when the objects are slightly separated. Caution: Reducing this value too far could cripple Unity’s ability to calculate continuous polygon collisions. Conversely, increasing the value too much could create artifacts for vertex collisions.
Simulation Mode Select when Unity executes the 2D physics simulation from the dropdown menu.
Fixed Update Select this to have Unity execute the physics simulation immediately after the MonoBehaviour.FixedUpdate is called.
Update Select this to have Unity execute the physics simulation immediately after the MonoBehaviour.Update is called.
脚本 Select this to manually execute the physics simulation via Physics2D.Simulate.
Queries Hit Triggers Enable this option if you want Collider 2Ds marked as Triggers to return a hit when any physics query (such as Linecasts or Raycasts) intersects with them. Defaults to enabled.
Queries Start In Colliders Enable this option if you want physics queries that start inside a Collider 2D to detect the Collider they start in.
Callbacks On Disable Enable this option to produce collision callbacks when a Collider with contacts is disabled.
Reuse Collision Callbacks 启用此设置将使物理引擎对所有碰撞回调重用单个 Collision2D 实例。如果将其禁用,则物理引擎会为每个碰撞回调创建一个新的 Collision2D 实例。
Auto Sync Transforms 启用此选项可自动将变换更改与物理系统同步。
Gizmos Select the types of physics 2D gizmos to be drawn within the Editor. You may select multiple options.
Nothing Select this to deselect every option. No physics 2D gizmo will be drawn.
Everything Select this to select every option.
All Colliders Select this to have all Colliders drawn without having to select them in the Hierarchy window.
Colliders Outlined Select this to have Colliders drawn with an outline (you can customize the outline’s color in 2D Physics Preferences).
Colliders Filled Select this to have all Colliders drawn using the Fill color specified in the 2D Physics Preferences.
Colliders Sleeping Select this to have Colliders drawn to show when the Rigidbody 2D they are attached to is sleeping using the Awake or Asleep colors specified in the 2D Physics Preferences.
Collider Contacts Select this to have Collider contacts shown as a directional arrow that starts at the contact point in the direction of the contact normal. You can specify the Contact color of the arrow in the 2D Physics Preferences.
Collider Bounds Select this to have Collider bounds drawn for all PhysicsShape2D that a Collider creates. The bounds are an Axis-Aligned Bounding Box (AABB).
Multithreading Expand this to adjust the multithreading settings. Refer to Multithreading for information about each property.


The settings in the Multithreading section allow you to use the C# Job System to configure multithreaded physics.

Multithreading settings expanded.
Multithreading settings expanded.
属性 功能
Use Multithreading 启用此选项会使用作业系统执行模拟步骤,并使用这些选项中的其余部分控制如何实现该功能。
Use Consistency Sorting 如果保持一致的处理顺序对于模拟十分重要,请启用此选项。
在多个 CPU 线程中执行模拟步骤会生成单独的数据批次。处理这些单独的批次会降低处理顺序的确定性,不过会生成更快的结果。
Interpolation Poses Per Job 设置在每个模拟作业中进行插值的最小 2D 刚体对象数。
New Contacts Per Job 设置在每个模拟作业中要查找的最小新接触数。
Collide Contacts Per Job 设置在每个模拟作业中要碰撞的最小接触数。
Clear Flags Per Job 设置在每个模拟作业中要清除的最小标志数。
Clear Body Forces Per Job 设置在每个模拟作业中要清除的最小实体数。
Sync Discrete Fixtures Per Job 设置在每个模拟作业的离散孤岛解算过程中,要在粗筛阶段中同步的最小灯具数。
Sync Continuous Fixtures Per Job 设置在每个模拟作业的连续孤岛解算过程中,要在粗筛阶段中同步的最小灯具数。
Find Nearest Contacts Per Job 设置在每个模拟作业中要查找的最小最近接触数。
Update Trigger Contacts Per Job 设置在每个模拟作业中要更新的最小触发器接触数。
Island Solver Cost Threshold 设置在离散孤岛解算过程中某个孤岛中所有实体、接触和关节的最小阈值成本。
Island Solver Body Cost Scale 设置在离散孤岛解算过程中每个实体的成本规模。
Island Solver Contact Cost Scale 设置在离散孤岛解算过程中每个接触的成本规模。
Island Solver Joint Cost Scale 设置在离散孤岛解算过程中每个关节的成本规模。
Island Solver Bodies Per Job 设置在执行孤岛解算时在每个模拟作业中要解算的最小实体数。
Island Solver Contacts Per Job 设置在执行孤岛解算时在每个模拟作业中要解算的最小接触数。

Layer Collision Matrix tab

The Layer Collision Matrix tab settings control whether Colliders (attached to different Rigidbody 2Ds) can come into contact which each other, based on the Layer assigned to the GameObject they are on. The matrix displays each Layer against every other Layer, allowing you to select which specific Layers can come into contact with another.

The Layer Collision Matrix tab.
The Layer Collision Matrix tab.

A check mark at the intersection between two Layers indicates that contact is allowed between those two Layers, while a cleared checkbox indicates that contact between those two Layers is never allowed. When you hover over a Layer’s name or a checkbox, its row and column are highlighted to make it easier to see which Layers its affects.

Tip: To optimize for the best possible performance, you should ensure that only the minimum number of potential contacts are selected by only selecting the specific Layers that you want to have contact with others, and disabling all other unnecessary contacts. To help with this, you can select Disable All or Enable All to quickly select or deselect all options at once. and then select the specific Layers.



物理 (Physics)