soft_body_attachments
A particle can also be attached directly to a rigid-body (SoftBody.attach_particle), which is
the simplest way of combining the two kinds of bodies: a rope tied to a swinging ball, a flag attached to its pole,
etc. Unlike pinning, an attachment is a two-way point-to-point constraint: the rigid-body holds the particle, and the
particle pulls the rigid-body back. The anchor is the position the particle has when the attachment is created,
expressed in the local frame of the rigid-body. Note that a particle attached twice keeps both of its attachments, and
that an attachment is undone with
SoftBody.detach_particle:
# Attach the last particle of a rope to a rigid ball, at the particle's position.
rope = rp.SoftBody.rope((-0.5, 5.0, 3.0), (2.5, 5.0, 3.0), 30).pinned_particles([0]).softness((40.0, 1.0))
rope_handle = world.add_soft_body(rope)
last_position = world.soft_bodies[rope_handle].particle_position(29)
ball = world.add_body(
rp.RigidBody.dynamic(translation=last_position - (0.0, 0.3, 0.0)),
colliders=[rp.Collider.ball(0.25).density(2.0)],
)
world.soft_bodies[rope_handle].attach_particle(29, ball, world.rigid_bodies)
Note that the rigid-body set of the world is given to SoftBody.attach_particle, so that the anchor can be expressed in
the local frame of the rigid-body. The attachments of a soft-body are listed by its particle_attachments property,
each SoftParticleAttachment giving its particle, its rigid-body (body), its local_anchor, and the impulse it
applied during the last step.