RayHit
Where a ray first hit something, filled in by PhysicsWorld.raycast. Make one and keep it, so a raycast allocates nothing.
toString gives what it hit and where, for example RayHit(RIGID_BODY, RigidBody(2), at=(120.0, 300.0), normal=(0.0, -1.0), fraction=0.4).
Samples
val world = PhysicsWorld()
val wall = world.rigidBody(Shape.box(10f, 100f), x = 100f, y = 0f, kind = BodyKind.STATIC)
// Make one RayHit and keep it: a raycast then allocates nothing.
val hit = RayHit()
val found = world.raycast(fromX = 0f, fromY = 0f, toX = 200f, toY = 0f, hit = hit, targets = QueryTargets.RIGID_BODIES)
assertPrints(found, "true")
assertPrints(hit.kind, "RIGID_BODY")
assertPrints(hit.rigidBodyOrNull == wall, "true")
// It hit the wall's left face, at x = 95, facing back towards the ray's start.
assertPrints(hit.x, "95.0")
assertPrints(hit.normalX, "-1.0")
assertPrints(world.raycast(0f, 0f, 50f, 0f, hit), "false")
assertPrints(hit.kind == HitKind.NOTHING, "true")Content copied to clipboard
Properties
Link copied to clipboard
What it hit, or HitKind.NOTHING.
Link copied to clipboard
The rigid body it hit, or null when it hit something else or nothing.
Link copied to clipboard
The shape of the rigid body it hit, or null when it hit something else or nothing.
Link copied to clipboard
The soft body it hit, or null when it hit something else or nothing.
Link copied to clipboard
The solid it hit, or null when it hit something else or nothing.