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.

CollisionObject3D

繼承: Node3D < Node < Object

被繼承: Area3D, PhysicsBody3D

3D 物理物件的抽象基底類別。

說明

3D 物理物件的抽象基底類別。CollisionObject3D 能夠容納任意數量的 Shape3D 用作碰撞形狀。每個形狀必須分配給一個形狀所有者。形狀所有者不是節點,也不會出現在編輯器中,但可以通過程式碼使用 shape_owner_* 方法存取。

警告:如果使用非均勻縮放,則該節點可能無法按預期工作。建議讓所有軸上的縮放保持一致,可以用對碰撞形狀的調整來代替非均勻縮放。

屬性

int

collision_layer

1

int

collision_mask

1

float

collision_priority

1.0

DisableMode

disable_mode

0

bool

input_capture_on_drag

false

bool

input_ray_pickable

true

方法

void

_input_event(camera: Camera3D, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) virtual

void

_mouse_enter() virtual

void

_mouse_exit() virtual

int

create_shape_owner(owner: Object)

bool

get_collision_layer_value(layer_number: int) const

bool

get_collision_mask_value(layer_number: int) const

RID

get_rid() const

PackedInt32Array

get_shape_owners()

bool

is_shape_owner_disabled(owner_id: int) const

void

remove_shape_owner(owner_id: int)

void

set_collision_layer_value(layer_number: int, value: bool)

void

set_collision_mask_value(layer_number: int, value: bool)

int

shape_find_owner(shape_index: int) const

void

shape_owner_add_shape(owner_id: int, shape: Shape3D)

void

shape_owner_clear_shapes(owner_id: int)

Object

shape_owner_get_owner(owner_id: int) const

Shape3D

shape_owner_get_shape(owner_id: int, shape_id: int) const

int

shape_owner_get_shape_count(owner_id: int) const

int

shape_owner_get_shape_index(owner_id: int, shape_id: int) const

Transform3D

shape_owner_get_transform(owner_id: int) const

void

shape_owner_remove_shape(owner_id: int, shape_id: int)

void

shape_owner_set_disabled(owner_id: int, disabled: bool)

void

shape_owner_set_transform(owner_id: int, transform: Transform3D)


訊號

input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) 🔗

Emitted when an unhandled input event occurs. Requires input_ray_pickable to be true and at least one collision_layer bit to be set. See _input_event() for details.


mouse_entered() 🔗

當滑鼠指標進入該物件的任何形狀時發出。要求 input_ray_pickable 為 true 並且至少設定了一個 collision_layer 位。

注意:由於缺少連續的碰撞偵測,如果滑鼠移動得足夠快並且 CollisionObject3D 的區域很小,則該訊號可能不會按預期的順序發出。如果另一個 CollisionObject3D 與所討論的 CollisionObject3D 重疊,則也可能不會發出該訊號。


mouse_exited() 🔗

當滑鼠指標離開該物件的所有形狀時發出。要求 input_ray_pickable 為 true 並且至少設定了一個 collision_layer 位。

注意:由於缺少連續的碰撞偵測,如果滑鼠移動得足夠快並且 CollisionObject3D 的區域很小,則該訊號可能不會按預期的順序發出。如果另一個 CollisionObject3D 與所討論的 CollisionObject3D 重疊,則也可能不會發出該訊號。


列舉

enum DisableMode: 🔗

DisableMode DISABLE_MODE_REMOVE = 0

當 Node.process_mode 被設定為 Node.PROCESS_MODE_DISABLED 時,從物理模擬中移除,停止與此 CollisionObject3D 的所有物理互動。

當該 Node 再次被處理時,會自動重新加入到物理模擬中。

DisableMode DISABLE_MODE_MAKE_STATIC = 1

當 Node.process_mode 被設定為 Node.PROCESS_MODE_DISABLED 時,使實體靜態化。不影響 Area3D。PhysicsBody3D 在靜態時不會受到力或其他實體的影響。

當該 Node 再次被處理時,自動將 PhysicsBody3D 設定回其原始模式。

DisableMode DISABLE_MODE_KEEP_ACTIVE = 2

當 Node.process_mode 被設定為 Node.PROCESS_MODE_DISABLED 時,不影響物理模擬。


屬性說明

int collision_layer = 1 🔗

  • void set_collision_layer(value: int)

  • int get_collision_layer()

The physics layers this CollisionObject3D is in. Collision objects can exist in one or more of 32 different layers. See also collision_mask. For an easier way to change this value from a script, see set_collision_layer_value().

Note: Object A can detect a contact with object B only if object B is in any of the layers that object A scans. See Collision layers and masks in the documentation for more information.


int collision_mask = 1 🔗

  • void set_collision_mask(value: int)

  • int get_collision_mask()

The physics layers this CollisionObject3D scans. Collision objects can scan one or more of 32 different layers. See also collision_layer. For an easier way to change this value from a script, see set_collision_mask_value().

Note: Object A can detect a contact with object B only if object B is in any of the layers that object A scans. See Collision layers and masks in the documentation for more information.


float collision_priority = 1.0 🔗

  • void set_collision_priority(value: float)

  • float get_collision_priority()

發生穿透時用於解決碰撞的優先順序。優先順序越高,對物體的穿透度就越低。例如,可以用來防止玩家突破關卡的邊界。


DisableMode disable_mode = 0 🔗

定義 Node.process_mode 為 Node.PROCESS_MODE_DISABLED 時的物理行為。


bool input_capture_on_drag = false 🔗

  • void set_capture_input_on_drag(value: bool)

  • bool get_capture_input_on_drag()

如果為 true,則當滑鼠拖過其形狀時,CollisionObject3D 將繼續接收輸入事件。


bool input_ray_pickable = true 🔗

  • void set_ray_pickable(value: bool)

  • bool is_ray_pickable()

如果為 true,則該對象是可拾取的。可拾取的物件可以偵測滑鼠指標的進入/離開,滑鼠位於其中時,就會報告輸入事件。要求至少設定一個 collision_layer 位。


方法說明

void _input_event(camera: Camera3D, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) virtual 🔗

Detects unhandled mouse and touch InputEvents through event when they happen while hovering over the object. Gesture events are not detected. camera is the Camera3D that the event originated in (for cameras inside viewports other than the main one to be detected, the parent Viewport.physics_object_picking needs to be set to true). event_position is the position hit by a raycast from the camera to the mouse, in global space. normal is the normal vector of the surface at that point in world space. shape_idx is the index of the detected shape from PhysicsServer3D.

See also Node._unhandled_input(), shape_find_owner(), and shape_owner_get_owner().

Note: InputEventScreenDrag events are triggered if the drag events started while hovering the object, or when the object is in the path of the drag event.

Note: _input_event() requires input_ray_pickable to be true and at least one collision_layer bit to be set.


void _mouse_enter() virtual 🔗

當滑鼠指標進入該實體的任何形狀時呼叫。要求 input_ray_pickable 為 true 並且至少設定一個 collision_layer 位。請注意,在單個 CollisionObject3D 中的不同形狀之間移動,不會導致該函式被呼叫。


void _mouse_exit() virtual 🔗

當滑鼠指標離開該實體的所有形狀時呼叫。要求 input_ray_pickable 為 true 並且至少設定一個 collision_layer 位。請注意,在單個 CollisionObject3D 中的不同形狀之間移動,不會導致該函式被呼叫。


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 get_rid() const 🔗

返回對象的 RID。


PackedInt32Array get_shape_owners() 🔗

返回一個 owner_id 識別字的 Array。你可以在其他使用 owner_id 作為參數的方法中使用這些 ID。


bool is_shape_owner_disabled(owner_id: int) const 🔗

如果為 true,則停用形狀所有者及其形狀。


void remove_shape_owner(owner_id: int) 🔗

移除給定形狀的所有者。


void set_collision_layer_value(layer_number: int, value: bool) 🔗

Based on value, enables or disables the specified layer in the collision_layer, given a layer_number between 1 and 32. This simplifies editing this CollisionObject3D's collision layer compared to assigning the collision_layer property directly.


void set_collision_mask_value(layer_number: int, value: bool) 🔗

Based on value, enables or disables the specified layer in the collision_mask, given a layer_number between 1 and 32. This simplifies editing this CollisionObject3D's collision mask compared to assigning the collision_mask property directly.


int shape_find_owner(shape_index: int) const 🔗

返回指定形狀的 owner_id。


void shape_owner_add_shape(owner_id: int, shape: Shape3D) 🔗

向形狀擁有者新增 Shape3D。


void shape_owner_clear_shapes(owner_id: int) 🔗

移除形狀所有者的所有形狀。


Object shape_owner_get_owner(owner_id: int) const 🔗

返回給定形狀所有者的父物件。


Shape3D shape_owner_get_shape(owner_id: int, shape_id: int) const 🔗

返回形狀所有者中具有給定 ID 的 Shape3D。


int shape_owner_get_shape_count(owner_id: int) const 🔗

返回給定形狀所有者包含的形狀數量。


int shape_owner_get_shape_index(owner_id: int, shape_id: int) const 🔗

返回形狀所有者中具有給定 ID 的 Shape3D 的子索引。


Transform3D shape_owner_get_transform(owner_id: int) const 🔗

返回形狀所有者的 Transform3D。


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_transform(owner_id: int, transform: Transform3D) 🔗

設定給定形狀所有者的 Transform3D。