SoftBodies
The soft bodies in a PhysicsWorld. A SoftBody handle names a group of the world's particles, a ring and a core, held together by the world's constraints:
an edge (distance) between each ring particle and the next: stiff, so the skin doesn't tear
a spoke (distance) from each ring particle to the core: soft, so it squashes and springs back
an area over the ring, so a squashed body bulges out elsewhere
Its particles and constraints are ordinary ones: reach them with particlesOf, coreOf, edgeOf and spokeOf.
toString gives how many soft bodies are alive, for example SoftBodies(size=5).
Samples
val world = PhysicsWorld()
// A floor of 16-unit tiles along row 9, its top at y = 144.
val grid = SolidGrid(columns = 20, rows = 10, tileSize = 16f)
for (column in 0 until 20) grid.fill(column, 9)
world.solids = grid
val slime = world.softBody(SoftBodyShape.semiDisc(13f, 14, 8, coreMass = 34f), centerX = 160f, baseY = 100f)
repeat(120) { world.step(1.seconds / 60) }
// It fell onto the floor and sits on it, its bottom at the floor's top.
assertTrue(world.softBodies.maxYOf(slime) in 140f..146f)
assertPrints(world.softBodies.isOnFloor(slime), "true")
assertPrints(world.softBodies.particlesOf(slime).size, "23")Functions
Adds a body of shape with its middle at centerX and its bottom on baseY, at rest, and returns its handle. Each ring particle weighs particleMass; the core is SoftBodyShape.coreMass times that. Pass the arguments after baseY by name.
Returns how many particles of body stood on a floor during the last step.
Returns the tags of every floor a particle of body stood on during the last step, together; SolidTags.NONE for none.
Returns the longest edge of body's ring as a multiple of its rest length: 1 at rest, large when it is tearing.
Returns the mean velocity of body's ring particles across, in units per second.
Returns the mean velocity of body's ring particles down, in units per second.
Returns the particles of body, its ring in order and then its core, as a new list.
Returns whether body's skin is kept from passing through itself: see setSelfCollision.
Puts every particle of body on layers, colliding with what is on a layer of mask and holds a layer of body's in its own mask: see PhysicsLayers. The layers say nothing about the solids: see setSolidCollision.
Sets whether body's skin is kept from passing through itself, as when it folds over. It is SelfCollision.PASS by default: a body that does not fold does not need it, and it costs a check of every ring particle against every edge.
Sets whether every particle of body is kept out of the solids, the SolidGrid and its moving solids. It is SolidCollision.COLLIDE by default; a SolidCollision.PASS body falls through the level.
Returns whether body is kept out of the solids: see setSolidCollision.
Returns how soft body was made.