grab

fun grab(x: Float, y: Float, reach: Float = Grab.REACH, compliance: Float = Grab.COMPLIANCE)(source)

Takes hold of the dynamic rigid body at (x, y), by that point, or else the movable particle nearest it, within reach, and pulls it towards that point with a soft pin until release. One thing at a time: grabbing again lets go of the last. Read what it holds from Grab.particleOrNull and Grab.bodyOrNull on hand.

Samples

val world = PhysicsWorld()
val crate = world.rigidBody(Shape.box(20f, 20f), x = 100f, y = 100f)

// Take the crate by its corner and drag it to the right.
world.grab(108f, 92f)
assertPrints(world.hand.bodyOrNull == crate, "true")
repeat(30) {
    world.moveGrab(200f, 92f)
    world.step(1.seconds / 60)
}
assertTrue(world.rigidBodies.xOf(crate) > 150f)

world.release()
assertPrints(world.hand.isHolding, "false")