Version: 2020.1
Hinge Joint
Rigidbody (Твердое тело)

Mesh Collider

The Mesh Collider takes a Mesh Asset and builds its Collider based on that Mesh. It is more accurate for collision detection than using primitives for complicated Meshes. Mesh Colliders that are marked as Convex can collide with other Mesh Colliders.

Свойства

Property Function
Convex Enable the checkbox to make the Mesh Collider collide with other Mesh Colliders. Convex Mesh Colliders are limited to 255 triangles.
Is Trigger Enable this checkbox to make Unity use this Collider for triggering events, and the physics engine ignore it.
Cooking Options Enable or disable the Mesh cooking options that affect how the physics engine processes Meshes.
None Disables all of the Cooking Options listed below.
Everything Enables all of the Cooking Options listed below.
Cook for Faster Simulation Makes the physics engine cook Meshes for faster simulation. When enabled, this runs some extra steps to guarantee the resulting Mesh is optimal for run-time performance. This affects the performance of the physics queries and contacts generation. When this setting is disabled, the physics engine uses a faster cooking time instead, and produces results as fast as possible. Consequently, the cooked Mesh Collider might not be optimal.
Enable Mesh Cleaning Makes the physics engine clean Meshes. When enabled, the cooking process tries to eliminate degenerate triangles of the Mesh, as well as other geometrical artifacts. This results in a Mesh that is better suited for use in collision detection and tends to produce more accurate hit points.
Weld Colocated Vertices Makes the physics engine remove equal vertices in the Meshes. When enabled, the physics engine combines the vertices that have the same position. This is important for the collision feedback that happens at run time.
Use Fast Midphase Makes the physics engine use the fastest mid-phase acceleration structure and algorithm available for your output platform. When you enable this option, the physics engine uses a faster algorithm that doesn’t require any R-Trees for spatial access. If you encounter mid-phase issues at runtime on some platform, you can still disable this option to use the slower legacy mid-phase algorithm instead.
Material Ссылка на физический материал, который определяет, как данный коллайдер взаимодействует с другими.
Mesh Ссылка на меш, используемый для столкновений.

Details

The Mesh Collider builds its collision representation from the Mesh attached to the GameObject, and reads the properties of the attached Transform to set its position and scale correctly. The benefit of this is that you can make the shape of the Collider exactly the same as the shape of the visible Mesh for the GameObject, which creates more precise and authentic collisions. However, this precision comes with a higher processing overhead than collisions involving primitive colliders (such as Sphere, Box, and Capsule), so it is best to use Mesh Colliders sparingly.

Faces in collision meshes are one-sided. This means GameObjects can pass through them from one direction, but collide with them from the other.

Details about underlying algorithms and data structures used by mesh colliders can be found at PhysX documentation.

Mesh cooking

Mesh cooking changes a normal Mesh into a Mesh that you can use in the physics engine. Cooking builds the spatial search structures for the physics queries, such as Physics.Raycast, as well as supporting structures for the contacts generation. Unity cooks all Meshes before using them in collision detection. This can happen at import time (Import Settings > Model > Generate Colliders) or at run time.

When you generate Meshes at run time (for example, for procedural surfaces), it’s useful to set the Cooking Options to produce results faster, and disable the additional data cleaning steps of cleaning. The downside is that you need to generate no degenerate triangles and no co-located vertices, but the cooking works faster.

If you disable Enable Mesh Cleaning or Weld Colocated Vertices, you need to ensure you aren’t using data that those algorithms would otherwise filter. Make sure you don’t have any co-located vertices if you have disabled Weld Colocated Vertices, and when you enable Enable Mesh Cleaning, make sure there are no tiny triangles whose area is close to zero, no thin triangles, and no huge triangles whose area is close to infinity.

Note: When you set the Cooking Options to any other value than the default settings, it means the Mesh Collider must use a Mesh that has an isReadable value of true.

Ограничения

There are some limitations when using the Mesh Collider:

GameObjects that have a Rigidbody component only support Mesh Colliders that have Convex option enabled: the physics engine can only simulate convex mesh colliders.

For a Mesh Collider to work properly, the Mesh must be read/write enabled in any of these circumstances:

  • The Mesh Collider’s Transform has negative scaling (for example, (–1, 1, 1)) and the Mesh is convex.
  • The Mesh Collider’s transform is skewed or sheared (for example, when a rotated transform has a scaled parent transform).
  • The Mesh Collider’s Cooking Options flags are set to any value other than the default.

You should not modify mesh geometry that is used for colliders because the physics engine has to rebuild an internal mesh collision acceleration structure every time you change the mesh. This causes a substantial performance overhead. For meshes that need to collide and change at runtime, it is often better to approximate the mesh shape with primitive colliders like capsules, spheres and boxes.

Optimization tip: If a Mesh Collider only uses a Mesh, you can disable Normals in Import Settings, because the physics system doesn’t need them.


  • Updated Mesh Collider limitations in 2018.3

  • 2018–10–12 Page amended

  • Mesh Cooking Options added in 2017.3 NewIn20173

  • Updated functionality in 2018.1

  • Updated limitations relating to read/write enabled setting in 2017.3

  • Inflate Convex Mesh deprecated in 2018.3 because the new convex hull computation algorithm (Quickhull) is more tolerant towards imperfections in the input mesh.

Hinge Joint
Rigidbody (Твердое тело)