RayCast

Inherits: Spatial < Node < Object

Category: Core

Brief Description

Query the closest object intersecting a ray.

Member Functions

void add_exception ( Object node )
void add_exception_rid ( RID rid )
void clear_exceptions ( )
void force_raycast_update ( )
Vector3 get_cast_to ( ) const
Object get_collider ( ) const
int get_collider_shape ( ) const
int get_collision_layer ( ) const
Vector3 get_collision_normal ( ) const
Vector3 get_collision_point ( ) const
int get_type_mask ( ) const
bool is_colliding ( ) const
bool is_enabled ( ) const
void remove_exception ( Object node )
void remove_exception_rid ( RID rid )
void set_cast_to ( Vector3 local_point )
void set_collision_layer ( int layer )
void set_enabled ( bool enabled )
void set_type_mask ( int mask )

Description

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.

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.

Only enabled raycasts will be able to query the space and report collisions!

RayCast calculates intersection every fixed frame (see 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 force_raycast_update after adjusting the raycast.

Member Function Description

  • void add_exception ( Object node )

Adds a collision exception so the ray does not report collisions with the specified node.

  • void add_exception_rid ( RID rid )
  • void clear_exceptions ( )

Removes all collision exception for this ray.

  • void force_raycast_update ( )

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.

Return the destination point of this ray object.

  • Object get_collider ( ) const

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 is_colliding to check if the object returned is actually colliding with the ray.

  • int get_collider_shape ( ) const

Returns the collision shape of the closest object the ray is pointing to.

  • Vector3 get_collision_normal ( ) const

Returns the normal of the intersecting object shape face containing the collision point.

  • Vector3 get_collision_point ( ) const

Returns collision point. This point is in global coordinate system.

  • int get_layer_mask ( ) const

Returns the layer mask for this ray.

  • int get_type_mask ( ) const

Returns the type mask (types of objects to detect) for this ray. The value is a sum (bitwise OR’d) of constants available for PhysicsDirectSpaceState.

  • bool is_colliding ( ) const

Return whether the closest object the ray is pointing to is colliding with the vector (considering the vector length).

  • bool is_enabled ( ) const

Returns whether this raycast is enabled or not.

  • void remove_exception ( Object node )

Removes a collision exception so the ray does report collisions with the specified node.

  • void remove_exception_rid ( RID rid )
  • void set_cast_to ( Vector3 local_point )

Sets to which point ray should be casted. This point is in local coordinate system.

  • void set_collision_layer ( int layer )

Set the mask to filter objects. Only objects with at least the same mask element set will be detected.

  • void set_enabled ( bool enabled )

Enables the RayCast2D. Only enabled raycasts will be able to query the space and report collisions.

  • void set_layer_mask ( int mask )

Set the mask to filter objects. Only objects with at least the same mask element set will be detected.

  • void set_type_mask ( int mask )

Set the types of objects to detect. For mask use a logic sum (OR operation) of constants defined in PhysicsDirectSpaceState, eg. PhysicsDirectSpaceState.TYPE_MASK_STATIC_BODY | PhysicsDirectSpaceState.TYPE_MASK_KINEMATIC_BODY to detect only those two types.