Magnets: Any Advice?

I’d like to improve the “snapping” feature of one of my games so that the pieces behave as if they are moving between magnets, and I’m wondering if any of the more experienced Unity coders here have any advice for me.

Specifically:

This is a sliding puzzle game in which game pieces are positioned on a grid of cells. The pieces slide from cell to cell. Currently this sliding behavior merely has the selected piece following mouse input and adjusts the piece to the nearest cell transform center when the mouse button is released.

However, I would like the piece to be drawn slightly toward the nearest cell while the mouse is down, so that while the player is dragging a selected piece, that piece shifts visually under the cursor toward the nearest grid cell (subject to a maximum value), just as if the piece is magnetic and the grid cells contain magnets.

What I’m looking for is some way of applying directional attractive force from one object onto another.

I realize this is subtle, but the purpose is to improve the feel of the game (and I care a great deal about feel).

Would you advise doing this through some form of joint and springiness? Or through checking the piece’s position in an Update method while mouse is down, and executing some Lerp translation to move the piece? Or something else entirely?

Thanks mates,
Neville

That’s probably the easiest and most direct means to achieve that effect (while the piece is being moved, use Lerp nudge the pure transform.x and .y values towards the closest drop point).