Sprite2D follow mouse and snap to Tile Grid

Godot Version



Hi. I have a Sprited2D that needs to follow the mouse cursor, additionally I need it to snap to the Tile grid that I have. I started by converting my mouse coordinates local_to_map and then setting the position of the sprite to that value but it does not work correctly.

The Sprite does move but as the cursor moves further away it gets out of sync.

I am new to programming, I apologize if the question is not put properly.