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:
- Example 2D
- Example 3D
// Attach the last particle of a rope to a rigid box, at the particle's position.
let rope = SoftBodyBuilder::rope(Vector::new(8.0, 9.0), Vector::new(12.0, 9.0), 25)
.pinned_particles([0])
.softness(SpringCoefficients::new(40.0, 1.0));
let rope_handle = world.insert_soft_body(rope);
let last_position = world.soft_bodies[rope_handle].particle_position(24);
let (weight, _) = world.insert(
RigidBodyBuilder::dynamic().translation(last_position - Vector::new(0.0, 0.4)),
ColliderBuilder::cuboid(0.3, 0.3).density(2.0),
);
world.soft_bodies[rope_handle].attach_particle(24, weight, &world.bodies);
// Attach the last particle of a rope to a rigid ball, at the particle's position.
let rope = SoftBodyBuilder::rope(Vector::new(-0.5, 5.0, 3.0), Vector::new(2.5, 5.0, 3.0), 30)
.pinned_particles([0])
.softness(SpringCoefficients::new(40.0, 1.0));
let rope_handle = world.insert_soft_body(rope);
let last_position = world.soft_bodies[rope_handle].particle_position(29);
let (ball, _) = world.insert(
RigidBodyBuilder::dynamic().translation(last_position - Vector::new(0.0, 0.3, 0.0)),
ColliderBuilder::ball(0.25).density(2.0),
);
world.soft_bodies[rope_handle].attach_particle(29, ball, &world.bodies);