Have you considered creating a command that works like the Snap_to_grid plugin BAz made for PGM? It would be fantastic to have a command that works like that plugin, for example, to center on the grid of a staircase and avoid so many calculations. The plugin also allowed you to adjust pixels in X and Y if needed. You can find the plugin creator here, so what are you waiting for?![]()
Haha, I’ll look into it!
Try this script out and use InvokeScript to call it where you need it. Comes with a debug system to visual it as well if you need it. Supports isometric tiles too!
snap_to_grid.gd (8.3 KB)
To use:
- Put the .gd in your project
- Create a Node2D on the object you want to snap and attach the script to it
- Setup the inspector so it knows the object to snap, snap type, tile size, etc
- Use InvokeScript action to use snap_to_nearest_grid
Thank you so much for your effort. I’ve tested it, and these are my conclusions. After trying several projects, I’ve concluded that the script works in top-view games, but it doesn’t work well in side-scrolling games because it tries to “bury” the character in the ground, causing the screen to shake, which is very annoying. Trying to correct it with the Y parameter doesn’t work correctly either. I think the error is that it tries to center the character on both the X and Y axes simultaneously, causing it to try to bury the character, and the collision detection tries to prevent this. I think a solution would be to provide an option to center the X and Y axes independently, allowing you to choose whether to center on X, Y, or both. I don’t know if the sprite size also plays a role
… In any case, such a command should be integrated and functional in the engine. Thanks again for your effort, BAZ.
(PS: I hope what I’m saying is more or less understandable since it was translated into English with Google Translate :P)
Well, I took the liberty of modifying the script, and after struggling with an AI for a while, I managed to add the options for only moving in x or y. It seems the problem lay in how Godot handles the physics of AnimatedSprite2D. After several attempts and corrections to eliminate the ghosting that occurred when changing the character’s position, it seems to be working. But as I said before, this should be an engine command because if we continue down this path, many things will be done through scripts and not with native engine commands, and I don’t think that’s the spirit of these engines. Besides, there will be users who won’t even know these solutions exist.
snapto_grid2.zip (2,1 KB)
I also modified to have options of snapping both, x only, or y only.
I couldn’t replicate the AnimatedSprite2D issue you were having (this sample uses it), so if you could further explain how to replicate that I can look into why.
I understand this should be doable by default, but the fact we can make a quick thing to fix while waiting for official solution (which is currently reported) is a good thing. Users will find them, just like they found all the RPG Maker plugins of old.
snap_to_grid.gd (8.3 KB)
It’s working fine now, thanks!![]()

