:github_url: hide .. Generated automatically by doc/tools/makerst.py in Godot's source tree. .. DO NOT EDIT THIS FILE, but the CollisionObject2D.xml source instead. .. The source is found in doc/classes or modules//doc_classes. .. _class_CollisionObject2D: CollisionObject2D ================= **Inherits:** :ref:`Node2D` **<** :ref:`CanvasItem` **<** :ref:`Node` **<** :ref:`Object` **Inherited By:** :ref:`Area2D`, :ref:`PhysicsBody2D` **Category:** Core Brief Description ----------------- Base node for 2D collision objects. Properties ---------- +-------------------------+------------------------------------------------------------------------+ | :ref:`bool` | :ref:`input_pickable` | +-------------------------+------------------------------------------------------------------------+ Methods ------- +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`_input_event` **(** :ref:`Object` viewport, :ref:`InputEvent` event, :ref:`int` shape_idx **)** virtual | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`create_shape_owner` **(** :ref:`Object` owner **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`RID` | :ref:`get_rid` **(** **)** const | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`get_shape_owner_one_way_collision_margin` **(** :ref:`int` owner_id **)** const | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Array` | :ref:`get_shape_owners` **(** **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_shape_owner_disabled` **(** :ref:`int` owner_id **)** const | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_shape_owner_one_way_collision_enabled` **(** :ref:`int` owner_id **)** const | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`remove_shape_owner` **(** :ref:`int` owner_id **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`shape_find_owner` **(** :ref:`int` shape_index **)** const | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`shape_owner_add_shape` **(** :ref:`int` owner_id, :ref:`Shape2D` shape **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`shape_owner_clear_shapes` **(** :ref:`int` owner_id **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Object` | :ref:`shape_owner_get_owner` **(** :ref:`int` owner_id **)** const | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Shape2D` | :ref:`shape_owner_get_shape` **(** :ref:`int` owner_id, :ref:`int` shape_id **)** const | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`shape_owner_get_shape_count` **(** :ref:`int` owner_id **)** const | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`shape_owner_get_shape_index` **(** :ref:`int` owner_id, :ref:`int` shape_id **)** const | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Transform2D` | :ref:`shape_owner_get_transform` **(** :ref:`int` owner_id **)** const | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`shape_owner_remove_shape` **(** :ref:`int` owner_id, :ref:`int` shape_id **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`shape_owner_set_disabled` **(** :ref:`int` owner_id, :ref:`bool` disabled **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`shape_owner_set_one_way_collision` **(** :ref:`int` owner_id, :ref:`bool` enable **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`shape_owner_set_one_way_collision_margin` **(** :ref:`int` owner_id, :ref:`float` margin **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`shape_owner_set_transform` **(** :ref:`int` owner_id, :ref:`Transform2D` transform **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Signals ------- .. _class_CollisionObject2D_signal_input_event: - **input_event** **(** :ref:`Node` viewport, :ref:`InputEvent` event, :ref:`int` shape_idx **)** Emitted when an input event occurs. Requires :ref:`input_pickable` to be ``true`` and at least one ``collision_layer`` bit to be set. See :ref:`_input_event` for details. ---- .. _class_CollisionObject2D_signal_mouse_entered: - **mouse_entered** **(** **)** Emitted when the mouse pointer enters any of this object's shapes. Requires :ref:`input_pickable` to be ``true`` and at least one ``collision_layer`` bit to be set. ---- .. _class_CollisionObject2D_signal_mouse_exited: - **mouse_exited** **(** **)** Emitted when the mouse pointer exits all this object's shapes. Requires :ref:`input_pickable` to be ``true`` and at least one ``collision_layer`` bit to be set. Description ----------- CollisionObject2D is the base class for 2D physics objects. It can hold any number of 2D collision :ref:`Shape2D`\ s. Each shape must be assigned to a *shape owner*. The CollisionObject2D can have any number of shape owners. Shape owners are not nodes and do not appear in the editor, but are accessible through code using the ``shape_owner_*`` methods. Property Descriptions --------------------- .. _class_CollisionObject2D_property_input_pickable: - :ref:`bool` **input_pickable** +----------+---------------------+ | *Setter* | set_pickable(value) | +----------+---------------------+ | *Getter* | is_pickable() | +----------+---------------------+ If ``true``, this object is pickable. A pickable object can detect the mouse pointer entering/leaving, and if the mouse is inside it, report input events. Requires at least one ``collision_layer`` bit to be set. Method Descriptions ------------------- .. _class_CollisionObject2D_method__input_event: - void **_input_event** **(** :ref:`Object` viewport, :ref:`InputEvent` event, :ref:`int` shape_idx **)** virtual Accepts unhandled :ref:`InputEvent`\ s. Requires :ref:`input_pickable` to be ``true``. ``shape_idx`` is the child index of the clicked :ref:`Shape2D`. Connect to the ``input_event`` signal to easily pick up these events. ---- .. _class_CollisionObject2D_method_create_shape_owner: - :ref:`int` **create_shape_owner** **(** :ref:`Object` owner **)** Creates a new shape owner for the given object. Returns ``owner_id`` of the new owner for future reference. ---- .. _class_CollisionObject2D_method_get_rid: - :ref:`RID` **get_rid** **(** **)** const Returns the object's :ref:`RID`. ---- .. _class_CollisionObject2D_method_get_shape_owner_one_way_collision_margin: - :ref:`float` **get_shape_owner_one_way_collision_margin** **(** :ref:`int` owner_id **)** const ---- .. _class_CollisionObject2D_method_get_shape_owners: - :ref:`Array` **get_shape_owners** **(** **)** Returns an :ref:`Array` of ``owner_id`` identifiers. You can use these ids in other methods that take ``owner_id`` as an argument. ---- .. _class_CollisionObject2D_method_is_shape_owner_disabled: - :ref:`bool` **is_shape_owner_disabled** **(** :ref:`int` owner_id **)** const If ``true``, the shape owner and its shapes are disabled. ---- .. _class_CollisionObject2D_method_is_shape_owner_one_way_collision_enabled: - :ref:`bool` **is_shape_owner_one_way_collision_enabled** **(** :ref:`int` owner_id **)** const Returns ``true`` if collisions for the shape owner originating from this ``CollisionObject2D`` will not be reported to collided with ``CollisionObject2D``\ s. ---- .. _class_CollisionObject2D_method_remove_shape_owner: - void **remove_shape_owner** **(** :ref:`int` owner_id **)** Removes the given shape owner. ---- .. _class_CollisionObject2D_method_shape_find_owner: - :ref:`int` **shape_find_owner** **(** :ref:`int` shape_index **)** const Returns the ``owner_id`` of the given shape. ---- .. _class_CollisionObject2D_method_shape_owner_add_shape: - void **shape_owner_add_shape** **(** :ref:`int` owner_id, :ref:`Shape2D` shape **)** Adds a :ref:`Shape2D` to the shape owner. ---- .. _class_CollisionObject2D_method_shape_owner_clear_shapes: - void **shape_owner_clear_shapes** **(** :ref:`int` owner_id **)** Removes all shapes from the shape owner. ---- .. _class_CollisionObject2D_method_shape_owner_get_owner: - :ref:`Object` **shape_owner_get_owner** **(** :ref:`int` owner_id **)** const Returns the parent object of the given shape owner. ---- .. _class_CollisionObject2D_method_shape_owner_get_shape: - :ref:`Shape2D` **shape_owner_get_shape** **(** :ref:`int` owner_id, :ref:`int` shape_id **)** const Returns the :ref:`Shape2D` with the given id from the given shape owner. ---- .. _class_CollisionObject2D_method_shape_owner_get_shape_count: - :ref:`int` **shape_owner_get_shape_count** **(** :ref:`int` owner_id **)** const Returns the number of shapes the given shape owner contains. ---- .. _class_CollisionObject2D_method_shape_owner_get_shape_index: - :ref:`int` **shape_owner_get_shape_index** **(** :ref:`int` owner_id, :ref:`int` shape_id **)** const Returns the child index of the :ref:`Shape2D` with the given id from the given shape owner. ---- .. _class_CollisionObject2D_method_shape_owner_get_transform: - :ref:`Transform2D` **shape_owner_get_transform** **(** :ref:`int` owner_id **)** const Returns the shape owner's :ref:`Transform2D`. ---- .. _class_CollisionObject2D_method_shape_owner_remove_shape: - void **shape_owner_remove_shape** **(** :ref:`int` owner_id, :ref:`int` shape_id **)** Removes a shape from the given shape owner. ---- .. _class_CollisionObject2D_method_shape_owner_set_disabled: - void **shape_owner_set_disabled** **(** :ref:`int` owner_id, :ref:`bool` disabled **)** If ``true``, disables the given shape owner. ---- .. _class_CollisionObject2D_method_shape_owner_set_one_way_collision: - void **shape_owner_set_one_way_collision** **(** :ref:`int` owner_id, :ref:`bool` enable **)** If ``enable`` is ``true``, collisions for the shape owner originating from this ``CollisionObject2D`` will not be reported to collided with ``CollisionObject2D``\ s. ---- .. _class_CollisionObject2D_method_shape_owner_set_one_way_collision_margin: - void **shape_owner_set_one_way_collision_margin** **(** :ref:`int` owner_id, :ref:`float` margin **)** ---- .. _class_CollisionObject2D_method_shape_owner_set_transform: - void **shape_owner_set_transform** **(** :ref:`int` owner_id, :ref:`Transform2D` transform **)** Sets the :ref:`Transform2D` of the given shape owner.