:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/4.1/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/4.1/doc/classes/RayCast3D.xml. .. _class_RayCast3D: RayCast3D ========= **Inherits:** :ref:`Node3D` **<** :ref:`Node` **<** :ref:`Object` A ray in 3D space, used to find the first :ref:`CollisionObject3D` it intersects. .. rst-class:: classref-introduction-group Description ----------- A raycast represents a ray from its origin to its :ref:`target_position` that finds the closest :ref:`CollisionObject3D` along its path, if it intersects any. This is useful for a lot of things, such as \ **RayCast3D** can ignore some objects by adding them to an exception list, by making its detection reporting ignore :ref:`Area3D`\ s (:ref:`collide_with_areas`) or :ref:`PhysicsBody3D`\ s (:ref:`collide_with_bodies`), or by configuring physics layers. \ **RayCast3D** calculates intersection every physics frame, and it holds the result until the next physics frame. For an immediate raycast, or if you want to configure a **RayCast3D** multiple times within the same physics frame, use :ref:`force_raycast_update`. To sweep over a region of 3D space, you can approximate the region with multiple **RayCast3D**\ s or use :ref:`ShapeCast3D`. .. rst-class:: classref-introduction-group Tutorials --------- - :doc:`Ray-casting <../tutorials/physics/ray-casting>` - `3D Voxel Demo `__ .. rst-class:: classref-reftable-group Properties ---------- .. table:: :widths: auto +-------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`bool` | :ref:`collide_with_areas` | ``false`` | +-------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`bool` | :ref:`collide_with_bodies` | ``true`` | +-------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`int` | :ref:`collision_mask` | ``1`` | +-------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`Color` | :ref:`debug_shape_custom_color` | ``Color(0, 0, 0, 1)`` | +-------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`int` | :ref:`debug_shape_thickness` | ``2`` | +-------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`bool` | :ref:`enabled` | ``true`` | +-------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`bool` | :ref:`exclude_parent` | ``true`` | +-------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`bool` | :ref:`hit_from_inside` | ``false`` | +-------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`Vector3` | :ref:`target_position` | ``Vector3(0, -1, 0)`` | +-------------------------------+------------------------------------------------------------------------------------+-----------------------+ .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_exception` **(** :ref:`CollisionObject3D` node **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_exception_rid` **(** :ref:`RID` rid **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`clear_exceptions` **(** **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`force_raycast_update` **(** **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Object` | :ref:`get_collider` **(** **)** |const| | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`RID` | :ref:`get_collider_rid` **(** **)** |const| | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_collider_shape` **(** **)** |const| | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`get_collision_mask_value` **(** :ref:`int` layer_number **)** |const| | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector3` | :ref:`get_collision_normal` **(** **)** |const| | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector3` | :ref:`get_collision_point` **(** **)** |const| | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_colliding` **(** **)** |const| | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`remove_exception` **(** :ref:`CollisionObject3D` node **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`remove_exception_rid` **(** :ref:`RID` rid **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_collision_mask_value` **(** :ref:`int` layer_number, :ref:`bool` value **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Property Descriptions --------------------- .. _class_RayCast3D_property_collide_with_areas: .. rst-class:: classref-property :ref:`bool` **collide_with_areas** = ``false`` .. rst-class:: classref-property-setget - void **set_collide_with_areas** **(** :ref:`bool` value **)** - :ref:`bool` **is_collide_with_areas_enabled** **(** **)** If ``true``, collision with :ref:`Area3D`\ s will be reported. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_property_collide_with_bodies: .. rst-class:: classref-property :ref:`bool` **collide_with_bodies** = ``true`` .. rst-class:: classref-property-setget - void **set_collide_with_bodies** **(** :ref:`bool` value **)** - :ref:`bool` **is_collide_with_bodies_enabled** **(** **)** If ``true``, collision with :ref:`PhysicsBody3D`\ s will be reported. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_property_collision_mask: .. rst-class:: classref-property :ref:`int` **collision_mask** = ``1`` .. rst-class:: classref-property-setget - void **set_collision_mask** **(** :ref:`int` value **)** - :ref:`int` **get_collision_mask** **(** **)** The ray's collision mask. Only objects in at least one collision layer enabled in the mask will be detected. See `Collision layers and masks <../tutorials/physics/physics_introduction.html#collision-layers-and-masks>`__ in the documentation for more information. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_property_debug_shape_custom_color: .. rst-class:: classref-property :ref:`Color` **debug_shape_custom_color** = ``Color(0, 0, 0, 1)`` .. rst-class:: classref-property-setget - void **set_debug_shape_custom_color** **(** :ref:`Color` value **)** - :ref:`Color` **get_debug_shape_custom_color** **(** **)** The custom color to use to draw the shape in the editor and at run-time if **Visible Collision Shapes** is enabled in the **Debug** menu. This color will be highlighted at run-time if the **RayCast3D** is colliding with something. If set to ``Color(0.0, 0.0, 0.0)`` (by default), the color set in :ref:`ProjectSettings.debug/shapes/collision/shape_color` is used. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_property_debug_shape_thickness: .. rst-class:: classref-property :ref:`int` **debug_shape_thickness** = ``2`` .. rst-class:: classref-property-setget - void **set_debug_shape_thickness** **(** :ref:`int` value **)** - :ref:`int` **get_debug_shape_thickness** **(** **)** If set to ``1``, a line is used as the debug shape. Otherwise, a truncated pyramid is drawn to represent the **RayCast3D**. Requires **Visible Collision Shapes** to be enabled in the **Debug** menu for the debug shape to be visible at run-time. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_property_enabled: .. rst-class:: classref-property :ref:`bool` **enabled** = ``true`` .. rst-class:: classref-property-setget - void **set_enabled** **(** :ref:`bool` value **)** - :ref:`bool` **is_enabled** **(** **)** If ``true``, collisions will be reported. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_property_exclude_parent: .. rst-class:: classref-property :ref:`bool` **exclude_parent** = ``true`` .. rst-class:: classref-property-setget - void **set_exclude_parent_body** **(** :ref:`bool` value **)** - :ref:`bool` **get_exclude_parent_body** **(** **)** If ``true``, collisions will be ignored for this RayCast3D's immediate parent. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_property_hit_from_inside: .. rst-class:: classref-property :ref:`bool` **hit_from_inside** = ``false`` .. rst-class:: classref-property-setget - void **set_hit_from_inside** **(** :ref:`bool` value **)** - :ref:`bool` **is_hit_from_inside_enabled** **(** **)** If ``true``, the ray will detect a hit when starting inside shapes. In this case the collision normal will be ``Vector3(0, 0, 0)``. Does not affect shapes with no volume like concave polygon or heightmap. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_property_target_position: .. rst-class:: classref-property :ref:`Vector3` **target_position** = ``Vector3(0, -1, 0)`` .. rst-class:: classref-property-setget - void **set_target_position** **(** :ref:`Vector3` value **)** - :ref:`Vector3` **get_target_position** **(** **)** The ray's destination point, relative to the RayCast's ``position``. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_RayCast3D_method_add_exception: .. rst-class:: classref-method void **add_exception** **(** :ref:`CollisionObject3D` node **)** Adds a collision exception so the ray does not report collisions with the specified :ref:`CollisionObject3D` node. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_method_add_exception_rid: .. rst-class:: classref-method void **add_exception_rid** **(** :ref:`RID` rid **)** Adds a collision exception so the ray does not report collisions with the specified :ref:`RID`. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_method_clear_exceptions: .. rst-class:: classref-method void **clear_exceptions** **(** **)** Removes all collision exceptions for this ray. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_method_force_raycast_update: .. rst-class:: classref-method void **force_raycast_update** **(** **)** Updates the collision information for the ray. Use this method to update the collision information immediately instead of waiting for the next ``_physics_process`` call, for example if the ray or its parent has changed state. \ **Note:** :ref:`enabled` does not need to be ``true`` for this to work. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_method_get_collider: .. rst-class:: classref-method :ref:`Object` **get_collider** **(** **)** |const| Returns the first object that the ray intersects, or ``null`` if no object is intersecting the ray (i.e. :ref:`is_colliding` returns ``false``). .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_method_get_collider_rid: .. rst-class:: classref-method :ref:`RID` **get_collider_rid** **(** **)** |const| Returns the :ref:`RID` of the first object that the ray intersects, or an empty :ref:`RID` if no object is intersecting the ray (i.e. :ref:`is_colliding` returns ``false``). .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_method_get_collider_shape: .. rst-class:: classref-method :ref:`int` **get_collider_shape** **(** **)** |const| Returns the shape ID of the first object that the ray intersects, or ``0`` if no object is intersecting the ray (i.e. :ref:`is_colliding` returns ``false``). To get the intersected shape node, for a :ref:`CollisionObject3D` target, use: .. tabs:: .. code-tab:: gdscript var target = get_collider() # A CollisionObject3D. var shape_id = get_collider_shape() # The shape index in the collider. var owner_id = target.shape_find_owner(shape_id) # The owner ID in the collider. var shape = target.shape_owner_get_owner(owner_id) .. code-tab:: csharp var target = (CollisionObject3D)GetCollider(); // A CollisionObject3D. var shapeId = GetColliderShape(); // The shape index in the collider. var ownerId = target.ShapeFindOwner(shapeId); // The owner ID in the collider. var shape = target.ShapeOwnerGetOwner(ownerId); .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_method_get_collision_mask_value: .. rst-class:: classref-method :ref:`bool` **get_collision_mask_value** **(** :ref:`int` layer_number **)** |const| Returns whether or not the specified layer of the :ref:`collision_mask` is enabled, given a ``layer_number`` between 1 and 32. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_method_get_collision_normal: .. rst-class:: classref-method :ref:`Vector3` **get_collision_normal** **(** **)** |const| Returns the normal of the intersecting object's shape at the collision point, or ``Vector3(0, 0, 0)`` if the ray starts inside the shape and :ref:`hit_from_inside` is ``true``. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_method_get_collision_point: .. rst-class:: classref-method :ref:`Vector3` **get_collision_point** **(** **)** |const| Returns the collision point at which the ray intersects the closest object. If :ref:`hit_from_inside` is ``true`` and the ray starts inside of a collision shape, this function will return the origin point of the ray. \ **Note:** This point is in the **global** coordinate system. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_method_is_colliding: .. rst-class:: classref-method :ref:`bool` **is_colliding** **(** **)** |const| Returns whether any object is intersecting with the ray's vector (considering the vector length). .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_method_remove_exception: .. rst-class:: classref-method void **remove_exception** **(** :ref:`CollisionObject3D` node **)** Removes a collision exception so the ray does report collisions with the specified :ref:`CollisionObject3D` node. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_method_remove_exception_rid: .. rst-class:: classref-method void **remove_exception_rid** **(** :ref:`RID` rid **)** Removes a collision exception so the ray does report collisions with the specified :ref:`RID`. .. rst-class:: classref-item-separator ---- .. _class_RayCast3D_method_set_collision_mask_value: .. rst-class:: classref-method void **set_collision_mask_value** **(** :ref:`int` layer_number, :ref:`bool` value **)** Based on ``value``, enables or disables the specified layer in the :ref:`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.)`