lua.box2d.world.cast
hits = world:cast(ray)
if ray.points is set then this is a polygon shape cast, otherwise this is an ray cast.
cast a ray and return an array of hits
ray.points
Tightly packed array of points for the shape. Maximum number of points
is B2_MAX_POLYGON_VERTICES (8) To cast a circle shape, just use a
radius and a single point at the origin.
ray.radius
Radius of the shape to cast, does not work unless you also set points.
ray.origin
Starting world point of ray
ray.translation
The ray to cast
ray.filter_categoryBits
ray.filter_maskBits
ray.filter
Filter masks, ray.filter is a previously set name that we will convert
using world:bits(name) into filter_categoryBits and filter_maskBits
unless they are already set.
hit=hits[1]
hit=hits[2]
etc
Returned hits which are sorted by fraction from low to high.
Initial overlaps are returned with a fraction of 0 and normal of 0. If you want the first actual hit you should ignore these and get the first hit with a non zero normal.
If hits[1] is nil then there where no hits.
hit.shapeID
BoxID of the shape we hit.
hit.shape
Table of the shape we hit. Filled in from shapeID for your convenience,
if somehow (?) shapeID is invalid then this will be nil. Shapes have a
uid that you can use to map shapes to game objects.
hit.fraction
0-1 value, indicating how far from the origin the ray traveled.
hit.point
Table containing world coordinates of the hit point.
hit.normal
Table containing shape normal at the hit point.
hits.leafVisits
hits.nodeVisits
Contain extra debug information