Skip to content

Targetting

targetForce is a composite force which pushes a thing toward a target position.

// Target the relative position of x:0.2, y:0.4
const targetForce = Forces.targetForce({x: 0.2, y: 0.4 });

It has some options. diminishBy scales the acceleration speed (default 0.0001). range allows you to skip moving if the thing is within this x/y to the target. Without range, it can easily ‘overshoot’ and end up bouncing back and forth around the target but never stopping.

const targetForce = Forces.targetForce(targetPos, {
diminishBy: 0.1,
range: { x: 0.01, y: 0.01} // If we're within 1% of target, that's good enough
});