CollisionShape2D

繼承: Node2D < CanvasItem < Node < Object

CollisionObject2D 父級提供 Shape2D 的節點。

說明

CollisionObject2D 父級提供 Shape2D 並允許對其進行編輯的節點。這可以為 Area2D 提供偵測形狀或將 PhysicsBody2D 轉變為實體物件。

教學

屬性

Color

debug_color

Color(0, 0, 0, 0)

bool

disabled

false

bool

one_way_collision

false

float

one_way_collision_margin

1.0

Shape2D

shape


屬性說明

Color debug_color = Color(0, 0, 0, 0) 🔗

  • void set_debug_color(value: Color)

  • Color get_debug_color()

The collision shape color that is displayed in the editor, or in the running project if Debug > Visible Collision Shapes is checked at the top of the editor.

Note: The default value is ProjectSettings.debug/shapes/collision/shape_color. The Color(0, 0, 0, 0) value documented here is a placeholder, and not the actual default debug color.


bool disabled = false 🔗

  • void set_disabled(value: bool)

  • bool is_disabled()

禁用的碰撞形狀在世界中沒有影響。這個屬性應該用 Object.set_deferred() 改變。


bool one_way_collision = false 🔗

  • void set_one_way_collision(value: bool)

  • bool is_one_way_collision_enabled()

設定此碰撞形狀是否僅應偵測到一側(頂部或底部)的碰撞。

注意:如果這個 CollisionShape2DArea2D 節點的子節點,則這個屬性無效。


float one_way_collision_margin = 1.0 🔗

  • void set_one_way_collision_margin(value: float)

  • float get_one_way_collision_margin()

用於單向碰撞的邊距(以圖元為單位)。較高的值將使形狀更厚,並且對於高速進入形狀的對撞機來說效果更好。


Shape2D shape 🔗

該碰撞形狀擁有的實際形狀。