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...
CollisionObject2D
繼承: Node2D < CanvasItem < Node < Object
被繼承: Area2D, PhysicsBody2D
2D 物理物件的抽象基底類別。
說明
2D 物理物件的抽象基底類別。CollisionObject2D 能夠容納任意數量的 Shape2D 用作碰撞形狀。每個形狀必須分配給一個形狀所有者。形狀所有者不是節點,也不會出現在編輯器中,但可以通過程式碼使用 shape_owner_* 方法存取。
注意:僅支援相同畫布中不同物件的碰撞(Viewport 畫布或 CanvasLayer)。不同畫布中的物件之間的碰撞行為是未定義的。
屬性
|
||
|
||
|
||
|
||
|
方法
訊號
input_event(viewport: Node, event: InputEvent, shape_idx: int) 🔗
當輸入事件發生時發出。要求 input_pickable 為 true 並且至少設定了一個 collision_layer 位。詳見 _input_event()。
mouse_entered() 🔗
當滑鼠指標進入該物件的任何形狀時發出。要求 input_pickable 為 true 並且至少設定了一個 collision_layer 位。請注意,在單個 CollisionObject2D 中的不同形狀之間移動,不會導致發出該訊號。
注意:由於缺少連續的碰撞偵測,如果滑鼠移動得足夠快並且 CollisionObject2D 的區域很小,則該訊號可能不會按預期的順序發出。如果另一個 CollisionObject2D 與所討論的 CollisionObject2D 重疊,則也可能不會發出該信號。
mouse_exited() 🔗
當滑鼠指標離開該物件的所有形狀時發出。要求 input_pickable 為 true 並且至少設定了一個 collision_layer 位。請注意,在單個 CollisionObject2D 中的不同形狀之間移動,不會導致發出該訊號。
注意:由於缺少連續的碰撞偵測,如果滑鼠移動得足夠快並且 CollisionObject2D 的區域很小,則該訊號可能不會按預期的順序發出。如果另一個 CollisionObject2D 與所討論的 CollisionObject2D 重疊,則也可能不會發出該信號。
mouse_shape_entered(shape_idx: int) 🔗
當滑鼠指標進入該實體的任何形狀或從一種形狀移動到另一種形狀時發出。shape_idx 是新進入的 Shape2D 的子索引。要求 input_pickable 為 true 並且至少設定一個 collision_layer 位。
mouse_shape_exited(shape_idx: int) 🔗
當滑鼠指標離開該實體的任何形狀時發出。shape_idx 是退出的 Shape2D 的子索引。要求 input_pickable 為 true 並且至少設定一個 collision_layer 位。
列舉
enum DisableMode: 🔗
DisableMode DISABLE_MODE_REMOVE = 0
當 Node.process_mode 被設定為 Node.PROCESS_MODE_DISABLED 時,從物理模擬中移除,停止與此 CollisionObject2D 的所有物理互動。
當該 Node 再次被處理時,會自動重新加入到物理模擬中。
DisableMode DISABLE_MODE_MAKE_STATIC = 1
當 Node.process_mode 被設定為 Node.PROCESS_MODE_DISABLED 時,使物體進入靜態模式。不影響 Area2D。處於靜態模式的 PhysicsBody2D 不會受到力和其他物體的影響。
當該 Node 再次被處理時,會自動將 PhysicsBody2D 設定回其原始模式。
DisableMode DISABLE_MODE_KEEP_ACTIVE = 2
當 Node.process_mode 被設定為 Node.PROCESS_MODE_DISABLED 時,不影響物理模擬。
屬性說明
此 CollisionObject2D 所在的實體層。碰撞物件可以存在於 32 個不同層中的一個或多個中。另見 collision_mask。
注意:只有當物件 B 在物件 A 掃描的任何層中時,物件 A 才能偵測到與物件 B 的接觸。有關更多資訊,請參閱文件中的《碰撞層與遮罩》。
此 CollisionObject2D 掃描的實體層。碰撞物件可以掃描 32 個不同層中的一個或多個。另見 collision_layer。
注意:只有當物件 B 在物件 A 掃描的任何層中時,物件 A 才能偵測到與物件 B 的接觸。有關更多資訊,請參閱文件中的《碰撞層與遮罩》。
float collision_priority = 1.0 🔗
發生穿透時用於解決碰撞的優先順序。優先順序越高,對物體的穿透度就越低。例如,可以用來防止玩家突破關卡的邊界。
DisableMode disable_mode = 0 🔗
void set_disable_mode(value: DisableMode)
DisableMode get_disable_mode()
Defines the behavior in physics when Node.process_mode is set to Node.PROCESS_MODE_DISABLED.
如果為 true,則該對象是可拾取的。可拾取的物件可以偵測滑鼠指標的進入/離開,滑鼠位於其中時,就會報告輸入事件。要求至少設定一個 collision_layer 位。
方法說明
void _input_event(viewport: Viewport, event: InputEvent, shape_idx: int) virtual 🔗
Accepts unhandled InputEvents. shape_idx is the child index of the clicked Shape2D. Connect to input_event to easily pick up these events.
Note: _input_event() requires input_pickable to be true and at least one collision_layer bit to be set.
void _mouse_enter() virtual 🔗
當滑鼠指標進入該實體的任何形狀時呼叫。要求 input_pickable 為 true 並且至少設定了一個 collision_layer 位。請注意,在單個 CollisionObject2D 中的不同形狀之間移動,不會導致該函式被呼叫。
void _mouse_exit() virtual 🔗
當滑鼠指標退出該實體的所有形狀時呼叫。要求 input_pickable 為 true 並且至少設定了一個 collision_layer 位。請注意,在單個 CollisionObject2D 中的不同形狀之間移動,不會導致該函式被呼叫。
void _mouse_shape_enter(shape_idx: int) virtual 🔗
當滑鼠指標進入該實體的任何形狀或從一個形狀移動到另一個形狀時呼叫。shape_idx 是新進入的 Shape2D 的子索引。要求 input_pickable 為 true 並且要至少設定一個 collision_layer 位。
void _mouse_shape_exit(shape_idx: int) virtual 🔗
當滑鼠指標離開該實體的任何形狀時呼叫。shape_idx 是退出的 Shape2D 的子索引。要求 input_pickable 為 true 並且至少要設定一個 collision_layer 位。
int create_shape_owner(owner: Object) 🔗
為給定物件建立一個新的形狀所有者。返回 owner_id的新所有者,供將來引用。
bool get_collision_layer_value(layer_number: int) const 🔗
返回 collision_layer 中是否啟用了指定的層,給定的 layer_number 應在 1 和 32 之間。
bool get_collision_mask_value(layer_number: int) const 🔗
返回 collision_mask 中是否啟用了指定的層,給定的 layer_number 應在 1 和 32 之間。
返回對象的 RID。
Vector2 get_shape_owner_one_way_collision_direction(owner_id: int) const 🔗
Returns the one_way_collision_direction of the shape owner identified by the given owner_id.
float get_shape_owner_one_way_collision_margin(owner_id: int) const 🔗
返回由給定 owner_id 標識的形狀所有者的 one_way_collision_margin。
PackedInt32Array get_shape_owners() 🔗
返回一個 owner_id 識別字的 Array。你可以在其他使用 owner_id 作為參數的方法中使用這些 ID。
bool is_shape_owner_disabled(owner_id: int) const 🔗
如果為 true,則禁用形狀所有者及其形狀。
bool is_shape_owner_one_way_collision_enabled(owner_id: int) const 🔗
返回 true,如果源於這個 CollisionObject2D 的形狀所有者的碰撞不會被報告給 CollisionObject2D。
void remove_shape_owner(owner_id: int) 🔗
移除給定形狀的所有者。
void set_collision_layer_value(layer_number: int, value: bool) 🔗
根據 value,啟用或禁用 collision_layer 中指定的層,給定的 layer_number 應在 1 和 32 之間。
void set_collision_mask_value(layer_number: int, value: bool) 🔗
根據 value,啟用或禁用 collision_mask 中指定的層,給定的 layer_number 應在 1 和 32 之間。
int shape_find_owner(shape_index: int) const 🔗
返回指定形狀的 owner_id。
void shape_owner_add_shape(owner_id: int, shape: Shape2D) 🔗
給形狀所有者新增一個 Shape2D。
void shape_owner_clear_shapes(owner_id: int) 🔗
移除形狀所有者的所有形狀。
Object shape_owner_get_owner(owner_id: int) const 🔗
返回給定形狀所有者的父物件。
Shape2D shape_owner_get_shape(owner_id: int, shape_id: int) const 🔗
從給定形狀所有者返回具有給定 ID 的 Shape2D。
int shape_owner_get_shape_count(owner_id: int) const 🔗
返回給定形狀所有者包含的形狀數量。
int shape_owner_get_shape_index(owner_id: int, shape_id: int) const 🔗
從給定形狀所有者返回具有給定 ID 的 Shape2D 的子索引。
Transform2D shape_owner_get_transform(owner_id: int) const 🔗
返回形狀所有者的 Transform2D。
void shape_owner_remove_shape(owner_id: int, shape_id: int) 🔗
從給定的形狀所有者中移除一個形狀。
void shape_owner_set_disabled(owner_id: int, disabled: bool) 🔗
如果為 true,則禁用給定的形狀所有者。
void shape_owner_set_one_way_collision(owner_id: int, enable: bool) 🔗
如果 enable 為 true,則源自該 CollisionObject2D 的形狀所有者的碰撞將不會被報告為與 CollisionObject2D 發生碰撞。
void shape_owner_set_one_way_collision_direction(owner_id: int, direction: Vector2) 🔗
Sets the one_way_collision_direction of the shape owner identified by the given owner_id to direction.
void shape_owner_set_one_way_collision_margin(owner_id: int, margin: float) 🔗
將由給定 owner_id 標識的形狀所有者的 one_way_collision_margin 設定為 margin 圖元。
void shape_owner_set_transform(owner_id: int, transform: Transform2D) 🔗
設定給定形狀所有者的 Transform2D。