Line Cast 2D
Last updated
Last updated
Casts a line segment against Colliders in the Scene.
A linecast is an imaginary line between two points in world space. Any object making contact with this line can be detected and reported. This differs from the similar raycast in that raycasting specifies the line using an origin and direction.
Linecasts are useful for determining lines of sight, targets hit by gunfire and for many other purposes in gameplay.
Additionally, this will also detect Collider(s) at the start of the line. In this case the line is starting inside the Collider and doesn't intersect the Collider surface. This means that the collision normal cannot be calculated in which case the collision normal returned is set to the inverse of the line vector being tested. This can easily be detected because such results are always at a RaycastHit2D fraction of zero.
This function returns a RaycastHit2D object when the line contacts a Collider in the Scene. The direction of the line is assumed to extend from the start point to the end point. Only the first Collider encountered in that direction will be reported.
To create it, right-click on free space in AI Tree inspector and select Create Node/Tasks/Physics2D/Line 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
Start
Origin of the Line Cast 2D
End
End of the Line Cast 2D
Culling Layer
Used to selectively ignore colliders when casting a Capsule Cast 2D
Node Name - node name.
Ignore Abort Self
Start - origin of the Line Cast 2D
End - end of the Line Cast 2D
Culling Layer - used to selectively ignore colliders when casting a Line Cast 2D
Message
Value of message
Argument
Argument of message in