KtxRayCastCallback

typealias KtxRayCastCallback = (fixture: Fixture, point: Vector2, normal: Vector2, fraction: Float) -> Float

Callback lambda for ray-casts.

This lambda is called for each fixture the ray-cast hits.

There is no guarantee on the order of the callback is called, e.g. the first call to the lambda is not necessarily the nearest to the start point of the ray.

The lambda accepts these parameters:

  • Fixture, the fixture hit by the ray.

  • Vector2, the point of initial intersection.

  • Vector2, the normal vector at the point of intersection.

  • Float, the fraction of the distance from start to end that the intersection point is at.

The lambda returns the new length of the ray as a fraction of the distance between the start and end or the ray. Common values are:

  • -1f, ignore this fixture and continue.

  • 0f, terminate the ray cast.

  • A fraction, clip the length of the ray to this point.

  • 1f, don't clip the ray and continue.

Can be used in place of com.badlogic.gdx.physics.box2d.RayCastCallback via Kotlin SAM conversion.

See also