Box Cast 2D
Node description and basic instructions
Last updated
Node description and basic instructions
Last updated
Casts a box against Colliders in the Scene, returning the first Collider to contact with it.
A Box Cast is conceptually like dragging a box through the Scene in a particular direction. Any object making contact with the box can be detected and reported. This function returns a RaycastHit2D object with a reference to the Collider that is hit by the box (the Collider property of the result will be NULL if nothing was hit). The layerMask can be used to detect objects selectively only on certain layers (this allows you to apply the detection only to enemy characters, for example). Box Cast has a size option. This defines how large the box is. The box is fired through the world. The larger the box is the more GameObjects will be hit. Box Cast also has a angle option. The box which is fired through the elements in the game can be rotated. This means that the collision between the Box Cast and a GameObject can be more hard to observe. The Box Cast direction variable determines how the Box moves in the Game. This is a 2D variable controlling the horizontal and vertical directions. Distance controls how far from the origin the Box travels. It may interact with many Colliders or none. In these cases the closest Collider2D provides the values set in the RaycastHit2D variable. If no Collider2D is hit then NULL is returned.
The returned RaycastHit2D returns both the point and normal of the contact where the box would touch the Collider. It also returns the centroid where the box would be positioned for it to contact at that point.
To create it, right-click on free space in AI Tree inspector and select Create Node/Tasks/Physics2D/Box Cast 2D.
This task node has a number of fields, that are highlighted in picture below.
Node Name
Name of node
Ignore Abort Self
Whether node ignores abort self or not
Origin
Origin of the Box Cast 2D
Direction
Direction in which to cast the box
Size
Size of the Box Cast 2D
Max Distance
Max length of the cast (by default: infinity)
Culling Layer
Used to selectively ignore colliders when casting a Box Cast 2D
Message
Value of message
Argument
Argument of message in