ShapeCast2D
Hereda: Node2D < CanvasItem < Node < Object
A 2D shape that sweeps a region of space to detect CollisionObject2Ds.
Descripción
Shape casting allows to detect collision objects by sweeping its shape along the cast direction determined by target_position. This is similar to 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 target_position set to Vector2(0, 0) and by calling force_shapecast_update() within the same physics frame. This helps to overcome some limitations of 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.
Propiedades
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Métodos
void |
add_exception(node: CollisionObject2D) |
void |
add_exception_rid(rid: RID) |
void |
|
void |
|
get_collider(index: int) const |
|
get_collider_rid(index: int) const |
|
get_collider_shape(index: int) const |
|
get_collision_count() const |
|
get_collision_mask_value(layer_number: int) const |
|
get_collision_normal(index: int) const |
|
get_collision_point(index: int) const |
|
is_colliding() const |
|
void |
|
void |
remove_exception_rid(rid: RID) |
void |
set_collision_mask_value(layer_number: int, value: bool) |
Descripciones de Propiedades
bool collide_with_areas = false 🔗
Si es true, se informará de las colisiones con Area2Ds.
bool collide_with_bodies = true 🔗
Si es true, se informará de las colisiones con PhysicsBody2Ds.
The shape'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.
Array get_collision_result()
Devuelve la información completa de la colisión del barrido de colisión. Los datos devueltos son los mismos que en el método PhysicsDirectSpaceState2D.get_rest_info().
Si es true, se informará de las colisiones.
Si es true, el nodo padre será excluido de la detección de colisiones.
El margen de colisión de la forma. Un margen más grande ayuda a detectar colisiones de forma más consistente, a costa de la precisión.
El número de intersecciones se puede limitar con este parámetro, para reducir el tiempo de procesamiento.
La forma que se usará para las consultas de colisión.
Vector2 target_position = Vector2(0, 50) 🔗
El punto de destino de la forma, relativo a la Node2D.position de este nodo.
Descripciones de Métodos
void add_exception(node: CollisionObject2D) 🔗
Añade una excepción de colisión para que la forma no reporte colisiones con el nodo especificado.
void add_exception_rid(rid: RID) 🔗
Añade una excepción de colisión para que la forma no reporte colisiones con el RID especificado.
void clear_exceptions() 🔗
Elimina todas las excepciones de colisión para esta forma.
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: Setting enabled to true is not required for this to work.
float get_closest_collision_safe_fraction() const 🔗
Returns the fraction from this cast's origin to its target_position of how far the shape can move without triggering a collision, as a value between 0.0 and 1.0.
float get_closest_collision_unsafe_fraction() const 🔗
Returns the fraction from this cast's origin to its target_position of how far the shape must move to trigger a collision, as a value between 0.0 and 1.0.
In ideal conditions this would be the same as get_closest_collision_safe_fraction(), however shape casting is calculated in discrete steps, so the precise point of collision can occur between two calculated positions.
Object get_collider(index: int) const 🔗
Returns the collided Object of one of the multiple collisions at index, or null if no object is intersecting the shape (i.e. is_colliding() returns false).
RID get_collider_rid(index: int) const 🔗
Returns the RID of the collided object of one of the multiple collisions at index.
int get_collider_shape(index: int) 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. is_colliding() returns false).
int get_collision_count() const 🔗
El número de colisiones detectadas en el punto de impacto. Utiliza esto para iterar sobre múltiples colisiones como las proporcionadas por los métodos get_collider(), get_collider_shape(), get_collision_point() y get_collision_normal().
bool get_collision_mask_value(layer_number: int) const 🔗
Devuelve si la capa especificada de collision_mask está habilitada o no, dado un layer_number entre 1 y 32.
Vector2 get_collision_normal(index: int) const 🔗
Devuelve la normal de una de las múltiples colisiones en index del objeto que se interseca.
Vector2 get_collision_point(index: int) const 🔗
Devuelve el punto de colisión de una de las múltiples colisiones en index donde la forma se interseca con el objeto que colisiona.
Nota: Este punto está en el sistema de coordenadas global.
Returns whether any object is intersecting with the shape's vector (considering the vector length).
void remove_exception(node: CollisionObject2D) 🔗
Removes a collision exception so the shape does report collisions with the specified node.
void remove_exception_rid(rid: RID) 🔗
Removes a collision exception so the shape does report collisions with the specified RID.
void set_collision_mask_value(layer_number: int, value: bool) 🔗
Basado en value, habilita o deshabilita la capa especificada en collision_mask, dado un layer_number entre 1 y 32.