Custom Physics Shape component
The PhysicsShapeAuthoring
component can model seven different collision shape types. The following table describes each one, in order of least computationally intensive to most computationally intensive.
Shape | Description |
---|---|
Sphere | A single point with a 3D radius. This is the simplest and least computationally intensive collision shape. |
Capsule | A single line with a 3D radius. |
Plane | A flat plane with four sides. This is similar to a quad in graphics, but all 4 corner vertices are coplanar. |
Box | A 3D cube shape. |
Cylinder | A convex hull with a 3D cylindrical shape. See Convex Hull, below. |
Convex Hull | A 'convex hull' is as if you wrapped the object in paper, all the holes and concave parts will not be represented, just the outer most features (see the teapot example below). Collision detection algorithms for something you know is convex is much faster than concave. |
Mesh | A set of arbitrarily arranged triangles that make up the shape of the mesh. A Mesh Collider is concave by default. This is the most complex and most computationally intensive collision shape, and collisions between two Mesh Colliders are particularly resource-heavy. It is best practice to use Mesh Colliders for kinematic (or static) objects, and convex shapes for dynamic objects. If you know that your Mesh Collider does not need to collide with another mesh, then you can make it dynamic, but you must set up your collision filtering appropriately. |
Example: how a convex hull looks like for a Utah teapot.
Additionally, Unity Physics supports Compound collider shapes. This is a combination of the above shapes that behaves as one Physics Body. This feature is useful in cases where an object has a complicated mesh, but the shape can be approximated using a few simpler colliders to improve performance. You can find more info about this below.
Note
In order to non-uniformly scale shapes at runtime as explained in the Collider documentation, the Force Unique
property in the shape's Physics Shape
authoring component must be checked. This makes sure that the collider in this shape is not shared with another shape that contains an identical collider. This is done by default for performance optimization purposes.
Optimize collisions with a bevel radius
To improve the performance and robustness of collision detection, you can configure Unity Physics to generate contacts within a small tolerance of the surface of a convex shape. This area of tolerance is referred to as a bevel radius.
To create this bevel radius, Unity Physics inflates a collider's hull to create a slightly larger outer shell, while aiming to preserve the original shape. It simultaneously inverts the collision geometry's vertices slightly, which creates rounded corners. These corners become more rounded the larger the bevel radius is, so you should aim to keep the bevel radius quite small.
Use the Bevel Radius property on a collider to set up an area of tolerance. The recommended default value is 0.05.
The Collider also stores a Material, which describes how it reacts when in collision with other objects.