Inherits: Node2D < CanvasItem < Node < Object
A 2D shape that sweeps a region of space to detect CollisionObject2Ds.
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.
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
|
void | add_exception ( CollisionObject2D node ) |
void | add_exception_rid ( RID rid ) |
void | clear_exceptions ( ) |
void | |
get_closest_collision_safe_fraction ( ) const | |
get_closest_collision_unsafe_fraction ( ) const | |
get_collider ( int index ) const | |
get_collider_rid ( int index ) const | |
get_collider_shape ( int index ) const | |
get_collision_count ( ) const | |
get_collision_mask_value ( int layer_number ) const | |
get_collision_normal ( int index ) const | |
get_collision_point ( int index ) const | |
is_colliding ( ) const | |
void | remove_exception ( CollisionObject2D node ) |
void | remove_exception_rid ( RID rid ) |
void | set_collision_mask_value ( int layer_number, bool value ) |
false
If true, collisions with Area2Ds will be reported.
true
If true, collisions with PhysicsBody2Ds will be reported.
1
The shape's collision mask. Only objects in at least one collision layer enabled in the mask will be detected.
[]
Returns the complete collision information from the collision sweep. The data returned is the same as in the PhysicsDirectSpaceState2D.get_rest_info method.
true
If true, collisions will be reported.
true
If true, the parent node will be excluded from collision detection.
0.0
The collision margin for the shape. A larger margin helps detecting collisions more consistently, at the cost of precision.
32
The number of intersections can be limited with this parameter, to reduce the processing time.
The Shape2D-derived shape to be used for collision queries.
Vector2(0, 50)
The shape's destination point, relative to this node's position.
Adds a collision exception so the shape does not report collisions with the specified CollisionObject2D node.
Adds a collision exception so the shape does not report collisions with the specified RID.
Removes all collision exceptions for this shape.
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: enabled == true is not required for this to work.
The fraction from the ShapeCast2D's origin to its target_position (between 0 and 1) of how far the shape can move without triggering a collision.
The fraction from the ShapeCast2D's origin to its target_position (between 0 and 1) of how far the shape must move to trigger a collision.
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).
Returns the RID of the collided object of one of the multiple collisions at index.
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).
The number of collisions detected at the point of impact. Use this to iterate over multiple collisions as provided by get_collider, get_collider_shape, get_collision_point, and get_collision_normal methods.
Returns whether or not the specified layer of the collision_mask is enabled, given a layer_number between 1 and 32.
Returns the normal of one of the multiple collisions at index of the intersecting object.
Returns the collision point of one of the multiple collisions at index where the shape intersects the colliding object.
Note: this point is in the global coordinate system.
Returns whether any object is intersecting with the shape's vector (considering the vector length).
Removes a collision exception so the shape does report collisions with the specified CollisionObject2D node.
Removes a collision exception so the shape does report collisions with the specified RID.
Based on value, enables or disables the specified layer in the collision_mask, given a layer_number between 1 and 32.
© 2014–present Juan Linietsky, Ariel Manzur and the Godot community
Licensed under the Creative Commons Attribution Unported License v3.0.
https://docs.godotengine.org/en/4.2/classes/class_shapecast2d.html