2D 胶囊碰撞体组件是一个可以在垂直或水平方向上伸长的 2D 物理基元。胶囊体形状没有顶角;它有连续的圆周,因此不容易卡在其他碰撞体角上。胶囊体形状为实心,因此完全位于胶囊体内部的任何其他 2D 碰撞体将视为与胶囊接触并且随着时间推移被迫离开胶囊。
属性: | 功能: |
---|---|
Material | 使用此属性来定义 2D 胶囊碰撞体使用的物理材质。此材质将覆盖所有 2D 刚体或全局物理碰撞体。 |
Is Trigger | 选中此框可指定 2D 胶囊碰撞体将触发事件。如果选中此框,物理引擎会忽略此碰撞体。 |
Used by Effector | 选中此框可指定附加的效应器将使用此 2D 胶囊碰撞体。 |
Offset | 使用此属性来设置 2D 胶囊碰撞体几何形状的局部偏移。 |
Size | 使用此属性来定义盒体大小。此盒体可指定 2D 胶囊碰撞体将填充的区域。 |
Direction | 将此属性设置为 Vertical 或 Horizontal。此属性控制围绕胶囊体的方向:具体而言,它定义了半圆形端盖的定位。 |
定义 2D 胶囊碰撞体的设置是 Size 和 Direction。Size 和 Direction 属性均表示 2D 胶囊碰撞体的局部空间中(而不是世界空间内)的 X 和 __Y__(分别为水平和垂直)。
设置 2D 胶囊碰撞体的一般方法是设置 Size 来匹配 Direction。例如,如果 2D 胶囊碰撞体的 Direction 为 Vertical__,__X 的 Size 为 0.5,且 Y 的 Size 为 1,这种设置将使垂直方向的胶囊体更高,而不是更宽。
在以下示例中,__X__ 和 Y 以黄线表示。
可使用不同的配置来更改 2D 胶囊碰撞体。以下是一些示例。
请注意,__Size__ 属性的 X 和 Y 相同时,2D 胶囊碰撞体始终近似于圆形。
物理引擎(包括 2D 盒体)中有一个已知问题,即多个碰撞体(甚至是在数字上完美对齐的碰撞体)之间的移动会导致一个或两个碰撞体在两个碰撞体之间记录碰撞。这可能导致碰撞体减速或停止。
虽然 2D 胶囊碰撞体可能有助于减少此问题,但并非此问题的解决方案。更好的解决方案是对表面使用单个碰撞体;例如,2D 边界碰撞体 (Edge Collider 2D)。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.