setMotor

fun setMotor(joint: Joint, speed: Float, maxTorque: Float)(source)

Drives hinge joint at speed radians a second, with at most maxTorque, or slider joint at speed units a second, with at most maxTorque as a force. A maxTorque of 0 turns the motor off. The speed is the second end's against the first, clockwise on screen, as angleOf counts: a wheel hinged to JointEnd.WORLD turns at -speed, since the world turns against the wheel.

Throws

if joint is not a hinge or a slider, or maxTorque is negative.

Samples

val world = PhysicsWorld()
val wheel = world.rigidBody(Shape.circle(10f), x = 0f, y = 0f)
val axle = world.joints.hinge(wheel, JointEnd.WORLD, x = 0f, y = 0f)
// Drives the world round the wheel at half a turn a second, so the wheel turns the other way.
world.joints.setMotor(axle, speed = PI.toFloat(), maxTorque = 1_000_000f)
repeat(60) { world.step(1.seconds / 60) }
assertPrints(world.rigidBodies.angularVelocityOf(wheel), "-3.1415927")