123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492 |
- :github_url: hide
- .. DO NOT EDIT THIS FILE!!!
- .. Generated automatically from Godot engine sources.
- .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
- .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/ShapeCast2D.xml.
- .. _class_ShapeCast2D:
- ShapeCast2D
- ===========
- **Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
- A 2D shape that sweeps a region of space to detect :ref:`CollisionObject2D<class_CollisionObject2D>`\ s.
- .. rst-class:: classref-introduction-group
- Description
- -----------
- Shape casting allows to detect collision objects by sweeping its :ref:`shape<class_ShapeCast2D_property_shape>` along the cast direction determined by :ref:`target_position<class_ShapeCast2D_property_target_position>`. This is similar to :ref:`RayCast2D<class_RayCast2D>`, but it allows for sweeping a region of space, rather than just a straight line. **ShapeCast2D** can detect multiple collision objects. It is useful for things like wide laser beams or snapping a simple shape to a floor.
- Immediate collision overlaps can be done with the :ref:`target_position<class_ShapeCast2D_property_target_position>` set to ``Vector2(0, 0)`` and by calling :ref:`force_shapecast_update<class_ShapeCast2D_method_force_shapecast_update>` within the same physics frame. This helps to overcome some limitations of :ref:`Area2D<class_Area2D>` when used as an instantaneous detection area, as collision information isn't immediately available to it.
- \ **Note:** Shape casting is more computationally expensive than ray casting.
- .. rst-class:: classref-reftable-group
- Properties
- ----------
- .. table::
- :widths: auto
- +-------------------------------+----------------------------------------------------------------------------+--------------------+
- | :ref:`bool<class_bool>` | :ref:`collide_with_areas<class_ShapeCast2D_property_collide_with_areas>` | ``false`` |
- +-------------------------------+----------------------------------------------------------------------------+--------------------+
- | :ref:`bool<class_bool>` | :ref:`collide_with_bodies<class_ShapeCast2D_property_collide_with_bodies>` | ``true`` |
- +-------------------------------+----------------------------------------------------------------------------+--------------------+
- | :ref:`int<class_int>` | :ref:`collision_mask<class_ShapeCast2D_property_collision_mask>` | ``1`` |
- +-------------------------------+----------------------------------------------------------------------------+--------------------+
- | :ref:`Array<class_Array>` | :ref:`collision_result<class_ShapeCast2D_property_collision_result>` | ``[]`` |
- +-------------------------------+----------------------------------------------------------------------------+--------------------+
- | :ref:`bool<class_bool>` | :ref:`enabled<class_ShapeCast2D_property_enabled>` | ``true`` |
- +-------------------------------+----------------------------------------------------------------------------+--------------------+
- | :ref:`bool<class_bool>` | :ref:`exclude_parent<class_ShapeCast2D_property_exclude_parent>` | ``true`` |
- +-------------------------------+----------------------------------------------------------------------------+--------------------+
- | :ref:`float<class_float>` | :ref:`margin<class_ShapeCast2D_property_margin>` | ``0.0`` |
- +-------------------------------+----------------------------------------------------------------------------+--------------------+
- | :ref:`int<class_int>` | :ref:`max_results<class_ShapeCast2D_property_max_results>` | ``32`` |
- +-------------------------------+----------------------------------------------------------------------------+--------------------+
- | :ref:`Shape2D<class_Shape2D>` | :ref:`shape<class_ShapeCast2D_property_shape>` | |
- +-------------------------------+----------------------------------------------------------------------------+--------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`target_position<class_ShapeCast2D_property_target_position>` | ``Vector2(0, 50)`` |
- +-------------------------------+----------------------------------------------------------------------------+--------------------+
- .. rst-class:: classref-reftable-group
- Methods
- -------
- .. table::
- :widths: auto
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`add_exception<class_ShapeCast2D_method_add_exception>` **(** :ref:`CollisionObject2D<class_CollisionObject2D>` node **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`add_exception_rid<class_ShapeCast2D_method_add_exception_rid>` **(** :ref:`RID<class_RID>` rid **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`clear_exceptions<class_ShapeCast2D_method_clear_exceptions>` **(** **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`force_shapecast_update<class_ShapeCast2D_method_force_shapecast_update>` **(** **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`get_closest_collision_safe_fraction<class_ShapeCast2D_method_get_closest_collision_safe_fraction>` **(** **)** |const| |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`get_closest_collision_unsafe_fraction<class_ShapeCast2D_method_get_closest_collision_unsafe_fraction>` **(** **)** |const| |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Object<class_Object>` | :ref:`get_collider<class_ShapeCast2D_method_get_collider>` **(** :ref:`int<class_int>` index **)** |const| |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`RID<class_RID>` | :ref:`get_collider_rid<class_ShapeCast2D_method_get_collider_rid>` **(** :ref:`int<class_int>` index **)** |const| |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`get_collider_shape<class_ShapeCast2D_method_get_collider_shape>` **(** :ref:`int<class_int>` index **)** |const| |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`get_collision_count<class_ShapeCast2D_method_get_collision_count>` **(** **)** |const| |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`get_collision_mask_value<class_ShapeCast2D_method_get_collision_mask_value>` **(** :ref:`int<class_int>` layer_number **)** |const| |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`get_collision_normal<class_ShapeCast2D_method_get_collision_normal>` **(** :ref:`int<class_int>` index **)** |const| |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`get_collision_point<class_ShapeCast2D_method_get_collision_point>` **(** :ref:`int<class_int>` index **)** |const| |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_colliding<class_ShapeCast2D_method_is_colliding>` **(** **)** |const| |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`remove_exception<class_ShapeCast2D_method_remove_exception>` **(** :ref:`CollisionObject2D<class_CollisionObject2D>` node **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`remove_exception_rid<class_ShapeCast2D_method_remove_exception_rid>` **(** :ref:`RID<class_RID>` rid **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_collision_mask_value<class_ShapeCast2D_method_set_collision_mask_value>` **(** :ref:`int<class_int>` layer_number, :ref:`bool<class_bool>` value **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Property Descriptions
- ---------------------
- .. _class_ShapeCast2D_property_collide_with_areas:
- .. rst-class:: classref-property
- :ref:`bool<class_bool>` **collide_with_areas** = ``false``
- .. rst-class:: classref-property-setget
- - void **set_collide_with_areas** **(** :ref:`bool<class_bool>` value **)**
- - :ref:`bool<class_bool>` **is_collide_with_areas_enabled** **(** **)**
- If ``true``, collisions with :ref:`Area2D<class_Area2D>`\ s will be reported.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_property_collide_with_bodies:
- .. rst-class:: classref-property
- :ref:`bool<class_bool>` **collide_with_bodies** = ``true``
- .. rst-class:: classref-property-setget
- - void **set_collide_with_bodies** **(** :ref:`bool<class_bool>` value **)**
- - :ref:`bool<class_bool>` **is_collide_with_bodies_enabled** **(** **)**
- If ``true``, collisions with :ref:`PhysicsBody2D<class_PhysicsBody2D>`\ s will be reported.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_property_collision_mask:
- .. rst-class:: classref-property
- :ref:`int<class_int>` **collision_mask** = ``1``
- .. rst-class:: classref-property-setget
- - void **set_collision_mask** **(** :ref:`int<class_int>` value **)**
- - :ref:`int<class_int>` **get_collision_mask** **(** **)**
- The shape's collision mask. Only objects in at least one collision layer enabled in the mask will be detected.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_property_collision_result:
- .. rst-class:: classref-property
- :ref:`Array<class_Array>` **collision_result** = ``[]``
- Returns the complete collision information from the collision sweep. The data returned is the same as in the :ref:`PhysicsDirectSpaceState2D.get_rest_info<class_PhysicsDirectSpaceState2D_method_get_rest_info>` method.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_property_enabled:
- .. rst-class:: classref-property
- :ref:`bool<class_bool>` **enabled** = ``true``
- .. rst-class:: classref-property-setget
- - void **set_enabled** **(** :ref:`bool<class_bool>` value **)**
- - :ref:`bool<class_bool>` **is_enabled** **(** **)**
- If ``true``, collisions will be reported.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_property_exclude_parent:
- .. rst-class:: classref-property
- :ref:`bool<class_bool>` **exclude_parent** = ``true``
- .. rst-class:: classref-property-setget
- - void **set_exclude_parent_body** **(** :ref:`bool<class_bool>` value **)**
- - :ref:`bool<class_bool>` **get_exclude_parent_body** **(** **)**
- If ``true``, the parent node will be excluded from collision detection.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_property_margin:
- .. rst-class:: classref-property
- :ref:`float<class_float>` **margin** = ``0.0``
- .. rst-class:: classref-property-setget
- - void **set_margin** **(** :ref:`float<class_float>` value **)**
- - :ref:`float<class_float>` **get_margin** **(** **)**
- The collision margin for the shape. A larger margin helps detecting collisions more consistently, at the cost of precision.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_property_max_results:
- .. rst-class:: classref-property
- :ref:`int<class_int>` **max_results** = ``32``
- .. rst-class:: classref-property-setget
- - void **set_max_results** **(** :ref:`int<class_int>` value **)**
- - :ref:`int<class_int>` **get_max_results** **(** **)**
- The number of intersections can be limited with this parameter, to reduce the processing time.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_property_shape:
- .. rst-class:: classref-property
- :ref:`Shape2D<class_Shape2D>` **shape**
- .. rst-class:: classref-property-setget
- - void **set_shape** **(** :ref:`Shape2D<class_Shape2D>` value **)**
- - :ref:`Shape2D<class_Shape2D>` **get_shape** **(** **)**
- The :ref:`Shape2D<class_Shape2D>`-derived shape to be used for collision queries.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_property_target_position:
- .. rst-class:: classref-property
- :ref:`Vector2<class_Vector2>` **target_position** = ``Vector2(0, 50)``
- .. rst-class:: classref-property-setget
- - void **set_target_position** **(** :ref:`Vector2<class_Vector2>` value **)**
- - :ref:`Vector2<class_Vector2>` **get_target_position** **(** **)**
- The shape's destination point, relative to this node's ``position``.
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Method Descriptions
- -------------------
- .. _class_ShapeCast2D_method_add_exception:
- .. rst-class:: classref-method
- void **add_exception** **(** :ref:`CollisionObject2D<class_CollisionObject2D>` node **)**
- Adds a collision exception so the shape does not report collisions with the specified :ref:`CollisionObject2D<class_CollisionObject2D>` node.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_add_exception_rid:
- .. rst-class:: classref-method
- void **add_exception_rid** **(** :ref:`RID<class_RID>` rid **)**
- Adds a collision exception so the shape does not report collisions with the specified :ref:`RID<class_RID>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_clear_exceptions:
- .. rst-class:: classref-method
- void **clear_exceptions** **(** **)**
- Removes all collision exceptions for this shape.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_force_shapecast_update:
- .. rst-class:: classref-method
- void **force_shapecast_update** **(** **)**
- Updates the collision information for the shape immediately, without waiting for the next ``_physics_process`` call. Use this method, for example, when the shape or its parent has changed state.
- \ **Note:** ``enabled == true`` is not required for this to work.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_get_closest_collision_safe_fraction:
- .. rst-class:: classref-method
- :ref:`float<class_float>` **get_closest_collision_safe_fraction** **(** **)** |const|
- The fraction from the **ShapeCast2D**'s origin to its :ref:`target_position<class_ShapeCast2D_property_target_position>` (between 0 and 1) of how far the shape can move without triggering a collision.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_get_closest_collision_unsafe_fraction:
- .. rst-class:: classref-method
- :ref:`float<class_float>` **get_closest_collision_unsafe_fraction** **(** **)** |const|
- The fraction from the **ShapeCast2D**'s origin to its :ref:`target_position<class_ShapeCast2D_property_target_position>` (between 0 and 1) of how far the shape must move to trigger a collision.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_get_collider:
- .. rst-class:: classref-method
- :ref:`Object<class_Object>` **get_collider** **(** :ref:`int<class_int>` index **)** |const|
- Returns the collided :ref:`Object<class_Object>` of one of the multiple collisions at ``index``, or ``null`` if no object is intersecting the shape (i.e. :ref:`is_colliding<class_ShapeCast2D_method_is_colliding>` returns ``false``).
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_get_collider_rid:
- .. rst-class:: classref-method
- :ref:`RID<class_RID>` **get_collider_rid** **(** :ref:`int<class_int>` index **)** |const|
- Returns the :ref:`RID<class_RID>` of the collided object of one of the multiple collisions at ``index``.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_get_collider_shape:
- .. rst-class:: classref-method
- :ref:`int<class_int>` **get_collider_shape** **(** :ref:`int<class_int>` index **)** |const|
- Returns the shape ID of the colliding shape of one of the multiple collisions at ``index``, or ``0`` if no object is intersecting the shape (i.e. :ref:`is_colliding<class_ShapeCast2D_method_is_colliding>` returns ``false``).
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_get_collision_count:
- .. rst-class:: classref-method
- :ref:`int<class_int>` **get_collision_count** **(** **)** |const|
- The number of collisions detected at the point of impact. Use this to iterate over multiple collisions as provided by :ref:`get_collider<class_ShapeCast2D_method_get_collider>`, :ref:`get_collider_shape<class_ShapeCast2D_method_get_collider_shape>`, :ref:`get_collision_point<class_ShapeCast2D_method_get_collision_point>`, and :ref:`get_collision_normal<class_ShapeCast2D_method_get_collision_normal>` methods.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_get_collision_mask_value:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **get_collision_mask_value** **(** :ref:`int<class_int>` layer_number **)** |const|
- Returns whether or not the specified layer of the :ref:`collision_mask<class_ShapeCast2D_property_collision_mask>` is enabled, given a ``layer_number`` between 1 and 32.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_get_collision_normal:
- .. rst-class:: classref-method
- :ref:`Vector2<class_Vector2>` **get_collision_normal** **(** :ref:`int<class_int>` index **)** |const|
- Returns the normal of one of the multiple collisions at ``index`` of the intersecting object.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_get_collision_point:
- .. rst-class:: classref-method
- :ref:`Vector2<class_Vector2>` **get_collision_point** **(** :ref:`int<class_int>` index **)** |const|
- Returns the collision point of one of the multiple collisions at ``index`` where the shape intersects the colliding object.
- \ **Note:** this point is in the **global** coordinate system.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_is_colliding:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **is_colliding** **(** **)** |const|
- Returns whether any object is intersecting with the shape's vector (considering the vector length).
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_remove_exception:
- .. rst-class:: classref-method
- void **remove_exception** **(** :ref:`CollisionObject2D<class_CollisionObject2D>` node **)**
- Removes a collision exception so the shape does report collisions with the specified :ref:`CollisionObject2D<class_CollisionObject2D>` node.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_remove_exception_rid:
- .. rst-class:: classref-method
- void **remove_exception_rid** **(** :ref:`RID<class_RID>` rid **)**
- Removes a collision exception so the shape does report collisions with the specified :ref:`RID<class_RID>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_ShapeCast2D_method_set_collision_mask_value:
- .. rst-class:: classref-method
- void **set_collision_mask_value** **(** :ref:`int<class_int>` layer_number, :ref:`bool<class_bool>` value **)**
- Based on ``value``, enables or disables the specified layer in the :ref:`collision_mask<class_ShapeCast2D_property_collision_mask>`, given a ``layer_number`` between 1 and 32.
- .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
- .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
- .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
- .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
- .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
- .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
- .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
|