attach
fun PhysicsWorld.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, so each drags the other, as a rope tied to a crate does. Returns the handle in PhysicsWorld.attachments.
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)Content copied to clipboard