Grab
A hand in the world, like a mouse's: it takes hold of one thing at a time and pulls it towards a point with a soft pin. That's a particle, or a rigid body by the point of it that was grabbed, so a crate picked up by its corner hangs from that corner. Use it through PhysicsWorld.grab, PhysicsWorld.moveGrab and PhysicsWorld.release.
However far the point jumps, the pin never pulls from further than maxPull away: at the start of every step its target is put back within maxPull of what it holds. So a mouse flung across the screen in one frame drags a body along quickly, but never yanks one particle out of it.
toString gives what it holds and where the hand is, for example Grab(particle=Particle(4), target=(120.0, 80.0)).
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")Content copied to clipboard