Skip to main content

Function: maintainPositionRelativeTo()

maintainPositionRelativeTo(mobject, target): UpdaterFunction

Defined in: animation/MaintainPositionRelativeTo.ts:28

Creates an updater function that maintains a mobject's position relative to a target. The offset is calculated when this function is called and preserved during updates.

Parameters

mobject

Mobject

The mobject to keep at a fixed offset

target

Mobject

The target mobject to track

Returns

UpdaterFunction

An updater function that can be added to a mobject with addUpdater()

Example

const follower = new Circle();
const leader = new Square();

// Keep follower 2 units to the right of leader
follower.moveTo([leader.position.x + 2, leader.position.y, 0]);
follower.addUpdater(maintainPositionRelativeTo(follower, leader));

// Now when leader moves, follower will follow