World:rayCastClosest

Available since LÖVE 12.0
This method is not supported in earlier versions.

Casts a ray and returns the intersection point of the closest Shape touched by the ray, if any.

World:rayCastAny is more efficient than World:rayCastClosest but will not always return the closest Shape.

Function

Synopsis

shape, x, y, xn, yn, fraction = World:rayCastClosest( x1, y1, x2, y2, categoryMaskBits )

Arguments

number x1
The x position of the starting point of the ray.
number y1
The y position of the starting point of the ray.
number x2
The x position of the end point of the ray.
number y2
The y position of the end point of the ray.
number categoryMaskBits (0xFFFF)
A bit-mask of categories the raycast can intersect with. Shapes with no categories that match any of this mask's bits will be ignored. This uses the same bit mask format as Shape:setFilterData. The default value intersects with all Shapes.

Returns

Shape shape
The Shape intersecting the ray, or nil if there was no intersection.
number x
The x position of the intersection point, or nil if there was no intersection.
number y
The y position of the intersection point, or nil if there was no intersection.
number xn
The x value of the surface normal vector of the shape edge, or nil if there was no intersection.
number yn
The y value of the surface normal vector of the shape edge, or nil if there was no intersection.
number fraction
The position of the intersection on the ray as a number from 0 to 1, or nil if there was no intersection.

See Also

Other Languages