UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

26 lines (21 loc) 574 B
/** * * @param {AABB2} box * @param {number} targetX target point X coordinate * @param {number} targetY target point Y coordinate * @param {number} strength */ export function pullBoxTowardsPoint( box, targetX, targetY, strength ) { const midX = box.centerX; const midY = box.centerY; const deltaX = targetX - midX; const deltaY = targetY - midY; //multiply by strength const displacementX = deltaX * strength; const displacementY = deltaY * strength; box.move(displacementX, displacementY); }