Fixture:rayCast
Casts a ray against the shape of the fixture and returns the surface normal vector and the line position where the ray hit. If the ray missed the shape, nil will be returned.

The ray starts on the first point of the input line and goes towards the second point of the line. The fifth argument is the maximum distance the ray is going to travel as a scale factor of the input line length.

The childIndex parameter is used to specify which child of a parent shape, such as a ChainShape, will be ray casted. For ChainShapes, the index of 1 is the first edge on the chain. Ray casting a parent shape will only test the child specified so if you want to test every shape of the parent, you must loop through all of its children.

The world position of the impact can be calculated by multiplying the line vector with the third return value and adding it to the line starting point.

hitx, hity = x1 + (x2 - x1) * fraction, y1 + (y2 - y1) * fraction
xn, yn, fraction = Fixture:rayCast( x1, y1, x2, y2, maxFraction, childIndex )
x1 number The x position of the input line starting point.
y1 number The y position of the input line starting point.
x2 number The x position of the input line end point.
y2 number The y position of the input line end point.
maxFraction number Ray length parameter.
childIndex (1) number The index of the child the ray gets cast against.
xn number The x component of the normal vector of the edge where the ray hit the shape.
yn number The y component of the normal vector of the edge where the ray hit the shape.
fraction number The position on the input line where the intersection happened as a factor of the line length.