Skip to content

Pendulum

The Forces.pendulumForce works with angular velocity and angle of a thing.

To use, we have to define a point by which the thing is pinned, and its distance.

const thing = {
position: { x: 0.5, y: 1 }
}
const pinnedAt = { x: 0.5, y: 0.5 };
const pendulumForce = Forces.pendulumForce(pinnedAt, { length: 0.4 });

The other options for the pendulum force are: damping, an amount to reduce velocity by, and speed, which is the maximum swing speed.

const pendulumForce = Forces.pendulumForce(pinnedAt, {
length: 0.4,
damping: 0.5, // default 0.995, ie 0.5% loss
speed: 0.1 // default 0.001
});

If length is not defined, the force will use the current distance between the target and thing.