attach

fun attach(particle: Particle, body: RigidBody, compliance: Float = 0.0f): Attachment(source)

Holds particle to body at the point where the particle is now, as softly as compliance, and returns the attachment's handle.

Throws

if particle or body is gone, or compliance is negative.

Samples

val world = PhysicsWorld()
val crate = world.rigidBody(Shape.box(20f, 20f), x = 100f, y = 0f)
val rope = world.rope(fromX = 0f, fromY = 0f, toX = 90f, toY = 0f, segments = 9)
// Ties the rope's free end to the crate's left face: the crate swings on the rope.
val knot = world.attach(rope.last, crate)
repeat(60) { world.step(1.seconds / 60) }
assertPrints(world.attachments.bodyOf(knot) == crate, "true")
assertTrue(world.rigidBodies.yOf(crate) > 20f)