distance
fun distance(a: RigidBody, b: JointEnd, ax: Float, ay: Float, bx: Float, by: Float, compliance: Float = 0.0f): Joint(source)
Holds the world point (ax, ay) of a and (bx, by) of b as far apart as they are now, as softly as compliance, and returns the joint's handle. Pass the points by name.
Throws
if an end is gone, b is a, or compliance is negative.
Samples
val world = PhysicsWorld()
val bob = world.rigidBody(Shape.circle(5f), x = 30f, y = 0f)
// A stick from the bob's middle to the world's origin, 30 long, as they are now.
world.joints.distance(bob, JointEnd.WORLD, ax = 30f, ay = 0f, bx = 0f, by = 0f)
repeat(60) { world.step(1.seconds / 60) }
val x = world.rigidBodies.xOf(bob)
val y = world.rigidBodies.yOf(bob)
assertTrue(kotlin.math.sqrt(x * x + y * y) in 29.5f..30.5f)Content copied to clipboard