RayCast¶
Inherits: Spatial < Node < Object
Busca el objeto más cercano que intersecta un rayo.
Descripción¶
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 along the path of the ray.
RayCast can ignore some objects by adding them to the exception list via add_exception
or by setting proper filtering with collision layers and masks.
RayCast can be configured to report collisions with Areas (collide_with_areas) and/or PhysicsBodys (collide_with_bodies).
Only enabled raycasts will be able to query the space and report collisions.
RayCast calculates intersection every physics frame (see Node), and the result is cached so it can be used later until the next frame. If multiple queries are required between physics frames (or during the same frame), use force_raycast_update after adjusting the raycast.
Tutoriales¶
Propiedades¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Métodos¶
void |
add_exception ( Object node ) |
void |
add_exception_rid ( RID rid ) |
void |
clear_exceptions ( ) |
void |
|
get_collider ( ) const |
|
get_collider_shape ( ) const |
|
get_collision_mask_bit ( int bit ) const |
|
get_collision_normal ( ) const |
|
get_collision_point ( ) const |
|
is_colliding ( ) const |
|
void |
remove_exception ( Object node ) |
void |
remove_exception_rid ( RID rid ) |
void |
set_collision_mask_bit ( int bit, bool value ) |
Descripciones de Propiedades¶
Vector3 cast_to
Default |
|
Setter |
set_cast_to(value) |
Getter |
get_cast_to() |
El punto de destino del rayo, relativo a la position
del RayCast.
bool collide_with_areas
Default |
|
Setter |
set_collide_with_areas(value) |
Getter |
is_collide_with_areas_enabled() |
If true
, collision with Areas will be reported.
bool collide_with_bodies
Default |
|
Setter |
set_collide_with_bodies(value) |
Getter |
is_collide_with_bodies_enabled() |
If true
, collision with PhysicsBodys will be reported.
int collision_mask
Default |
|
Setter |
set_collision_mask(value) |
Getter |
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 in the documentation for more information.
Color debug_shape_custom_color
Default |
|
Setter |
set_debug_shape_custom_color(value) |
Getter |
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 RayCast
is colliding with something.
If set to Color(0.0, 0.0, 0.0)
(by default), the color set in ProjectSettings.debug/shapes/collision/shape_color is used.
float debug_shape_thickness
Default |
|
Setter |
set_debug_shape_thickness(value) |
Getter |
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 RayCast
. Requires Visible Collision Shapes to be enabled in the Debug menu for the debug shape to be visible at run-time.
bool enabled
Default |
|
Setter |
set_enabled(value) |
Getter |
is_enabled() |
Si true
, se informará de las colisiones.
bool exclude_parent
Default |
|
Setter |
set_exclude_parent_body(value) |
Getter |
get_exclude_parent_body() |
If true
, collisions will be ignored for this RayCast's immediate parent.
Descripciones de Métodos¶
void add_exception ( Object node )
Añade una excepción de colisión para que el rayo no informe de las colisiones con el nodo especificado.
void add_exception_rid ( RID rid )
Añade una excepción de colisión para que el rayo no reporte colisiones con el RID especificado.
void clear_exceptions ( )
Elimina todas las excepciones de colisión para este rayo.
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: enabled
is not required for this to work.
Object get_collider ( ) const
Devuelve el primer objeto que el rayo intersecta, o null
si no hay ningún objeto que intersecte el rayo (es decir, is_colliding devuelve false
).
int get_collider_shape ( ) const
Devuelve el ID de la forma del primer objeto que el rayo intersecta, o 0
si no hay ningún objeto que intersecte el rayo (es decir, is_colliding devuelve false
).
Devuelve true
si el índice de bits pasado está activado.
Nota: Los índices de bits van de 0 a 19.
Vector3 get_collision_normal ( ) const
Devuelve la normalidad de la forma del objeto que se intersecta en el punto de colisión.
Vector3 get_collision_point ( ) const
Devuelve el punto de colisión en el que el rayo intersecta el objeto más cercano.
Nota: Este punto está en el sistema de coordenadas global.
bool is_colliding ( ) const
Devuelve si algún objeto se cruza con el vector del rayo (considerando la longitud del vector).
void remove_exception ( Object node )
Elimina una excepción de colisión para que el rayo informe de las colisiones con el nodo especificado.
void remove_exception_rid ( RID rid )
Elimina una excepción de colisión para que el rayo reporte colisiones con el RID especificado.
Establece el índice de bits pasado al value
pasado.
Nota: Los índices de bits van de 0 a 19.