Version: 2023.2
言語: 日本語
Edge Collider 2D component reference
Composite Collider 2D component reference

Capsule Collider 2D component reference

The Capsule Collider 2D component is a Collider 2D that interacts with the 2D physics system. The capsule shape of the collider, with its smooth, round circumference and absence of vertex corners, allows for smoother movement along other colliders, preventing snagging on sharp corners.

Note: The capsule shape of the collider is solid and not hollow. Unity regards any other Collider 2Ds that are inside the Capsule Collider 2D to be in constant contact with the collider and gradually forced out of the Capsule Collider 2D over time.

Capsule Collider 2D component Inspector window properties.
Capsule Collider 2D component Inspector window properties.
プロパティ 機能
Material 摩擦やバウンスなどの、衝突のプロパティを決定する Physics Material 2D を選択します。
Is Trigger この Collider 2D をトリガーとして動作させたい場合に有効にします。有効にした場合、物理演算システムはこのコライダーを無視します。
Used by Effector 添付された Effector 2D にこの Collider 2D を使用させたい場合に有効にします。
Composite Operations Select the composite operation used by an attached Composite Collider 2D component.

Note: When you select any operation besides None, the following properties—Material, Is Trigger, Used By Effector, and Edge Radius—become controlled by the attached Composite Collider 2D component and are no longer available in this collider’s properties.
None Select this to have no composite operation take place.
Merge Select this to have this composite operation compose geometry using a Boolean OR operation.
Intersect Select this to have this composite operation compose geometry using a Boolean AND operation.
Difference Select this to have this composite operation compose geometry using a Boolean NOT operation.
Flip Select this to have this composite operation compose geometry using a Boolean XOR operation.
Offset Collider 2D ジオメトリのローカルオフセット値を設定します。
Size X と Y の値を設定して、Capsule Collider 2D が埋めるボックス領域のサイズを定義します。詳しくはサイズと向きの定義 を参照してください。
Direction Capsule Collider 2D の向きを選択します。これにより、コライダー形状のカーブした両端の位置と向きが決まります。詳しくは サイズと向きの定義 を参照してください。
Vertical これを選択すると、コライダー形状の両端が上下に向きます。
Horizontal これを選択すると、コライダー形状の両端が左右に向きます。
Layer Overrides レイヤーのオーバーライド設定を展開します。
Layer Override Priority この Collider2D が、‘自身と他の Collision2D との接触が起こるべきかどうか’ について相反する決定が発生した場合の解決に使用する、決定の優先順位を割り当てます。詳細は API のページを参照してください。
Include Layers 他の Collider2D との接触が発生するかどうかを決定する際にこの Collider2D が含むべき、追加のレイヤーを選択します。詳細は API のドキュメントを参照してください。
Exclude Layers 他の Collider2D と接触するかどうかを決定する際にこの Collider2D が除外すべき、追加のレイヤーを選択します。詳細は API のドキュメントを参照してください。
Force Send Layers 他の Collider2D とのコリジョン接触中にこの Collider2D が力を送ることができるレイヤーを選択します。詳細は API のドキュメントを参照してください。
Force Receive Layers 他の Collider2D とのコリジョン接触中にこの Collider2D が力を受け取ることができるレイヤーを選択します。詳細は API のドキュメントを参照してください。
Contract Capture Layers この Collider2D と接触する他の Collider2D のレイヤーで、キャプチャされるものを選択します。詳細は API のドキュメントを参照してください。
Callback Layers この Collider2D が他の Collider2D との接触中に衝突を報告したりコールバックをトリガーするレイヤーを選択します。詳細は API のドキュメントを参照してください。

Defining size and direction

Capsule Collider 2D の形状を定義する設定は SizeDirection です。Size と Direction の両プロパティは、ワールド空間ではなく、Capsule Collider 2D のローカル空間の X (水平) と Y (垂直) を参照します。

Capsule Collider 2D の設定方法として代表的なのは、SizeDirection に合わせる方法です。例えば、 Capsule Collider 2D の DirectionVertical であれば、 XSize は 0.5、 YSize は 1 です。これにより、この垂直方向のカプセルは、(太くなるのではなく) 背が高くなります。

下記の例で、黄色い線で表されているのが XY です。

Size が Direction と一致するように設定された Capsule Collider 2D の例
SizeDirection と一致するように設定された Capsule Collider 2D の例

カプセルの設定例

Capsule Collider 2D の形状は様々に調整できます。以下で、以下はその一部です。

Size プロパティの XY が同じである場合は常に、 Capsule Collider 2D はほぼ円形になります。

Capsule Collider 2D の設定例
Capsule Collider 2D の設定例

ノート: 2D 物理システムの既知の問題として、ゲームオブジェクトが複数のコライダーを横切って移動すると、1 つまたは複数のコライダーがコライダー同士の衝突を登録することがあります。これは、コライダーが完全に整列している場合でも発生します。この衝突により、コライダーの速度が低下したり、停止したりする場合があります。

Capsule Collider 2D を使ってサーフェスを作成すると、この問題を軽減することができます。サーフェイスに複数のコライダーを使用するのではなく、1 つのコライダーを使用することをお勧めします。Edge Collider 2D はその例です。

その他の参考資料

CapsuleCollider2D

Edge Collider 2D component reference
Composite Collider 2D component reference