Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Shape2D¶
继承: Resource < RefCounted < Object
派生: CapsuleShape2D, CircleShape2D, ConcavePolygonShape2D, ConvexPolygonShape2D, RectangleShape2D, SegmentShape2D, SeparationRayShape2D, WorldBoundaryShape2D
用于物理碰撞的 2D 形状的抽象基类。
描述¶
所有 2D 形状的抽象基类,针对物理使用设计。
性能:对图元形状进行碰撞检测很快,尤其是 CircleShape2D。ConvexPolygonShape2D 较慢,ConcavePolygonShape2D 最慢。
教程¶
属性¶
|
方法¶
collide ( Transform2D local_xform, Shape2D with_shape, Transform2D shape_xform ) |
|
collide_and_get_contacts ( Transform2D local_xform, Shape2D with_shape, Transform2D shape_xform ) |
|
collide_with_motion ( Transform2D local_xform, Vector2 local_motion, Shape2D with_shape, Transform2D shape_xform, Vector2 shape_motion ) |
|
collide_with_motion_and_get_contacts ( Transform2D local_xform, Vector2 local_motion, Shape2D with_shape, Transform2D shape_xform, Vector2 shape_motion ) |
|
void |
|
get_rect ( ) const |
属性说明¶
float custom_solver_bias = 0.0
该形状的的自定义求解器偏差。定义了强制接触分离涉及到这个形状时,物体会做出多大的反应。
设为 0.0
时,使用的默认值为 ProjectSettings.physics/2d/solver/default_contact_bias。
方法说明¶
bool collide ( Transform2D local_xform, Shape2D with_shape, Transform2D shape_xform )
如果该形状与另一个形状发生碰撞,返回 true
。
本方法需要该形状的变换矩阵(local_xform
)、要检查与该形状碰撞的形状(with_shape
)、以及那个形状的变换矩阵(shape_xform
)。
PackedVector2Array collide_and_get_contacts ( Transform2D local_xform, Shape2D with_shape, Transform2D shape_xform )
返回该形状与另一形状接触的接触点对的列表。
如果不存在碰撞,则返回的列表为空。否则,返回的列表中包含的是成对排列的接触点,在该形状边界上的点和 with_shape
边界上的点之间交替排列。
有了碰撞对 A 和 B,就可以通过 (B - A).normalized()
计算碰撞法线,通过 (B - A).length()
计算碰撞深度。这些信息通常用于分离形状,在碰撞求解器中比较常见。
这个方法需要用到该形状的变换矩阵(local_xform
)、要检查与该形状是否碰撞的形状(with_shape
)、以及那个形状的变换矩阵(shape_xform
)。
bool collide_with_motion ( Transform2D local_xform, Vector2 local_motion, Shape2D with_shape, Transform2D shape_xform, Vector2 shape_motion )
返回应用给定的运动后,这个形状是否会与另一个形状发生碰撞。
这个方法需要这个形状的变换矩阵(local_xform
),要在这个形状上测试的运动(local_motion
),检查碰撞的形状(with_shape
),那个形状的变换矩阵(shape_xform
),以及用于测试其他物体的运动(shape_motion
)。
PackedVector2Array collide_with_motion_and_get_contacts ( Transform2D local_xform, Vector2 local_motion, Shape2D with_shape, Transform2D shape_xform, Vector2 shape_motion )
返回如果应用了给定的移动后,该形状将接触另一形状的接触点对列表。
如果不存在碰撞,则返回的列表为空。否则,返回的列表中包含的是成对排列的接触点,在该形状边界上的点和 with_shape
边界上的点之间会交替出现。
有了碰撞对 A 和 B,就可以通过 (B - A).normalized()
计算碰撞法线,通过 (B - A).length()
计算碰撞深度。这些信息通常用于分离形状,在碰撞求解器中比较常见。
本方法需要用到该形状的变换矩阵(local_xform
)、要在该形状上测试的运动(local_motion
)、要检查与该形状是否碰撞的形状(with_shape
)、那个形状的变换矩阵(shape_xform
)、以及要在其他形状上测试的运动(shape_motion
)。
void draw ( RID canvas_item, Color color )
用 RenderingServer API 在 CanvasItem 上绘制实体形状,并填充指定的颜色 color
。确切的绘制方法是每个形状特有的,无法配置。
Rect2 get_rect ( ) const
返回代表形状边界的 Rect2。