Up to date

This page is up to date for Godot `4.2`. If you still find outdated information, please open an issue.

# 碰撞形状（3D）¶

• Godot 3D 中可用的碰撞形状类型。

• 使用凸形或凹形网格作为碰撞形状.

• 有关3D碰撞的性能注意事项.

Godot提供多种碰撞形状, 具有不同的性能和精度权衡.

You can define the shape of a PhysicsBody3D by adding one or more CollisionShape3Ds as child nodes. Note that you must add a Shape3D resource to collision shape nodes in the Inspector dock.

## 基本碰撞形状¶

Godot提供了以下基本碰撞形状类型:

We recommend favoring primitive shapes for dynamic objects such as RigidBodies and CharacterBodies as their behavior is the most reliable. They often provide better performance as well.

## 凸型碰撞形状¶

Convex collision shapes are a compromise between primitive collision shapes and concave collision shapes. They can represent shapes of any complexity, but with an important caveat. As their name implies, an individual shape can only represent a convex shape. For instance, a pyramid is convex, but a hollow box is concave. To define a concave object with a single collision shape, you need to use a concave collision shape.

You can generate one or several convex collision shapes from the editor by selecting a MeshInstance3D and using the Mesh menu at the top of the 3D viewport. The editor exposes two generation modes:

• 创建单凸碰撞同级 使用Quickhull算法, 创建一个CollisionShape碰撞形状节点, 并自动生成一个凸碰撞形状, 由于只生成单个形状, 因此提供了良好的性能, 非常适合小对象.

• 创建多个凸形碰撞同级 使用V-HACD算法. 创建多个CollisionShape碰撞形状节点, 每个节点都有一个凸形, 由于它能生成多个形状, 所以对于凹形物体来说, 精度更高, 但性能不佳. 对于中等复杂度的对象, 可能会比使用单个凹形碰撞形状更快.

## 凹面或三面体碰撞形状¶

Concave collision shapes, also called trimesh collision shapes, can take any form, from a few triangles to thousands of triangles. Concave shapes are the slowest option but are also the most accurate in Godot. You can only use concave shapes within StaticBodies. They will not work with CharacterBodies or RigidBodies unless the RigidBody's mode is Static.

You can generate a concave collision shape from the editor by selecting a MeshInstance3D and using the Mesh menu at the top of the 3D viewport. The editor exposes two options:

• 创建三网格静态体是个方便的选择. 它创建一个包含与网格几何学匹配的凹形的静态体.

• 创建Trimesh(三角面)碰撞同级 创建具有与网格几何体匹配的凹面形状的CollisionShape(碰撞形状)节点.

See 导入 3D 场景 for information on how to export models for Godot and automatically generate collision shapes on import.

## 性能方面的注意事项¶

You aren't limited to a single collision shape per PhysicsBody. Still, we recommend keeping the number of shapes as low as possible to improve performance, especially for dynamic objects like RigidBodies and CharacterBodies. On top of that, avoid translating, rotating, or scaling CollisionShapes to benefit from the physics engine's internal optimizations.

When using a single non-transformed collision shape in a StaticBody, the engine's broad phase algorithm can discard inactive PhysicsBodies. The narrow phase will then only have to take into account the active bodies' shapes. If a StaticBody has many collision shapes, the broad phase will fail. The narrow phase, which is slower, must then perform a collision check against each shape.