class_raycast.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_RayCast:
  4. RayCast
  5. =======
  6. **Inherits:** :ref:`Spatial<class_spatial>` **<** :ref:`Node<class_node>` **<** :ref:`Object<class_object>`
  7. **Category:** Core
  8. Brief Description
  9. -----------------
  10. Query the closest object intersecting a ray.
  11. Member Functions
  12. ----------------
  13. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  14. | void | :ref:`add_exception<class_RayCast_add_exception>` **(** :ref:`Object<class_object>` node **)** |
  15. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  16. | void | :ref:`add_exception_rid<class_RayCast_add_exception_rid>` **(** :ref:`RID<class_rid>` rid **)** |
  17. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  18. | void | :ref:`clear_exceptions<class_RayCast_clear_exceptions>` **(** **)** |
  19. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  20. | void | :ref:`force_raycast_update<class_RayCast_force_raycast_update>` **(** **)** |
  21. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  22. | :ref:`Vector3<class_vector3>` | :ref:`get_cast_to<class_RayCast_get_cast_to>` **(** **)** const |
  23. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  24. | :ref:`Object<class_object>` | :ref:`get_collider<class_RayCast_get_collider>` **(** **)** const |
  25. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  26. | :ref:`int<class_int>` | :ref:`get_collider_shape<class_RayCast_get_collider_shape>` **(** **)** const |
  27. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  28. | :ref:`Vector3<class_vector3>` | :ref:`get_collision_normal<class_RayCast_get_collision_normal>` **(** **)** const |
  29. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  30. | :ref:`Vector3<class_vector3>` | :ref:`get_collision_point<class_RayCast_get_collision_point>` **(** **)** const |
  31. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  32. | :ref:`int<class_int>` | :ref:`get_layer_mask<class_RayCast_get_layer_mask>` **(** **)** const |
  33. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  34. | :ref:`int<class_int>` | :ref:`get_type_mask<class_RayCast_get_type_mask>` **(** **)** const |
  35. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  36. | :ref:`bool<class_bool>` | :ref:`is_colliding<class_RayCast_is_colliding>` **(** **)** const |
  37. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  38. | :ref:`bool<class_bool>` | :ref:`is_enabled<class_RayCast_is_enabled>` **(** **)** const |
  39. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  40. | void | :ref:`remove_exception<class_RayCast_remove_exception>` **(** :ref:`Object<class_object>` node **)** |
  41. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`remove_exception_rid<class_RayCast_remove_exception_rid>` **(** :ref:`RID<class_rid>` rid **)** |
  43. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  44. | void | :ref:`set_cast_to<class_RayCast_set_cast_to>` **(** :ref:`Vector3<class_vector3>` local_point **)** |
  45. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  46. | void | :ref:`set_enabled<class_RayCast_set_enabled>` **(** :ref:`bool<class_bool>` enabled **)** |
  47. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`set_layer_mask<class_RayCast_set_layer_mask>` **(** :ref:`int<class_int>` mask **)** |
  49. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`set_type_mask<class_RayCast_set_type_mask>` **(** :ref:`int<class_int>` mask **)** |
  51. +--------------------------------+---------------------------------------------------------------------------------------------------------+
  52. Description
  53. -----------
  54. A RayCast represents a line from its origin to its destination position ``cast_to``, it is used to query the 3D space in order to find the closest object intersecting with the ray.
  55. RayCast can ignore some objects by adding them to the exception list via ``add_exception``, setting proper filtering with layers, or by filtering object types with type masks.
  56. Only enabled raycasts will be able to query the space and report collisions!
  57. RayCast calculates intersection every fixed frame (see :ref:`Node<class_node>`), and the result is cached so it can be used later until the next frame. If multiple queries are required between fixed frames (or during the same frame) use :ref:`force_raycast_update<class_RayCast_force_raycast_update>` after adjusting the raycast.
  58. Member Function Description
  59. ---------------------------
  60. .. _class_RayCast_add_exception:
  61. - void **add_exception** **(** :ref:`Object<class_object>` node **)**
  62. Adds a collision exception so the ray does not report collisions with the specified ``node``.
  63. .. _class_RayCast_add_exception_rid:
  64. - void **add_exception_rid** **(** :ref:`RID<class_rid>` rid **)**
  65. .. _class_RayCast_clear_exceptions:
  66. - void **clear_exceptions** **(** **)**
  67. Removes all collision exception for this ray.
  68. .. _class_RayCast_force_raycast_update:
  69. - void **force_raycast_update** **(** **)**
  70. Updates the collision information in case if this object's properties changed during the current frame (for example position, rotation or the cast_point). Note, ``set_enabled`` is not required for this to work.
  71. .. _class_RayCast_get_cast_to:
  72. - :ref:`Vector3<class_vector3>` **get_cast_to** **(** **)** const
  73. Return the destination point of this ray object.
  74. .. _class_RayCast_get_collider:
  75. - :ref:`Object<class_object>` **get_collider** **(** **)** const
  76. Return the closest object the ray is pointing to. Note that this does not consider the length of the vector, so you must also use :ref:`is_colliding<class_RayCast_is_colliding>` to check if the object returned is actually colliding with the ray.
  77. .. _class_RayCast_get_collider_shape:
  78. - :ref:`int<class_int>` **get_collider_shape** **(** **)** const
  79. Returns the collision shape of the closest object the ray is pointing to.
  80. .. _class_RayCast_get_collision_normal:
  81. - :ref:`Vector3<class_vector3>` **get_collision_normal** **(** **)** const
  82. Returns the normal of the intersecting object shape face containing the collision point.
  83. .. _class_RayCast_get_collision_point:
  84. - :ref:`Vector3<class_vector3>` **get_collision_point** **(** **)** const
  85. Returns collision point. This point is in **global** coordinate system.
  86. .. _class_RayCast_get_layer_mask:
  87. - :ref:`int<class_int>` **get_layer_mask** **(** **)** const
  88. Returns the layer mask for this ray.
  89. .. _class_RayCast_get_type_mask:
  90. - :ref:`int<class_int>` **get_type_mask** **(** **)** const
  91. Returns the type mask (types of objects to detect) for this ray. The value is a sum (bitwise OR'd) of constants available for :ref:`PhysicsDirectSpaceState<class_physicsdirectspacestate>`.
  92. .. _class_RayCast_is_colliding:
  93. - :ref:`bool<class_bool>` **is_colliding** **(** **)** const
  94. Return whether the closest object the ray is pointing to is colliding with the vector (considering the vector length).
  95. .. _class_RayCast_is_enabled:
  96. - :ref:`bool<class_bool>` **is_enabled** **(** **)** const
  97. Returns whether this raycast is enabled or not.
  98. .. _class_RayCast_remove_exception:
  99. - void **remove_exception** **(** :ref:`Object<class_object>` node **)**
  100. Removes a collision exception so the ray does report collisions with the specified ``node``.
  101. .. _class_RayCast_remove_exception_rid:
  102. - void **remove_exception_rid** **(** :ref:`RID<class_rid>` rid **)**
  103. .. _class_RayCast_set_cast_to:
  104. - void **set_cast_to** **(** :ref:`Vector3<class_vector3>` local_point **)**
  105. Sets to which point ray should be casted. This point is in **local** coordinate system.
  106. .. _class_RayCast_set_enabled:
  107. - void **set_enabled** **(** :ref:`bool<class_bool>` enabled **)**
  108. Enables the RayCast2D. Only enabled raycasts will be able to query the space and report collisions.
  109. .. _class_RayCast_set_layer_mask:
  110. - void **set_layer_mask** **(** :ref:`int<class_int>` mask **)**
  111. Set the mask to filter objects. Only objects with at least the same mask element set will be detected.
  112. .. _class_RayCast_set_type_mask:
  113. - void **set_type_mask** **(** :ref:`int<class_int>` mask **)**
  114. Set the types of objects to detect. For ``mask`` use a logic sum (OR operation) of constants defined in :ref:`PhysicsDirectSpaceState<class_physicsdirectspacestate>`, eg. ``PhysicsDirectSpaceState.TYPE_MASK_STATIC_BODY | PhysicsDirectSpaceState.TYPE_MASK_KINEMATIC_BODY`` to detect only those two types.