softBody
fun PhysicsWorld.softBody(shape: SoftBodyShape, centerX: Float, baseY: Float, tuning: SoftBodyTuning = SoftBodyTuning(), material: Material = Material.DEFAULT): SoftBody(source)
Adds a soft body of shape with its middle at centerX and its bottom on baseY, and returns its handle in PhysicsWorld.softBodies.
Throws
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")Content copied to clipboard