Player won't snap to center of 64x64 grid

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By codelyoko373

Pretty much as the title says. I’m trying to snap a node/player to the center of a 64x64 grid just to make my life easier for some things. The issue is whenever I try, it only snaps to the corners or sides. Is this a bug or is there some setting I haven’t enabled?
enter image description here

I think there’s a way to make the center of the sprite the reference point.

Ertain | 2019-11-09 19:29

:bust_in_silhouette: Reply From: LoneDespair

You could configure snapping, can be found on top with 3 dots
or disable snapping by clicking on the magnet icon on top of your scene
or change the position via inspector

:bust_in_silhouette: Reply From: idbrii

These are the snap settings:

Godot 4.0.3 snap settings

Godot snaps to the grid guidelines and not the cells between them. So you won’t snap to the middle of the square that you’re dragging to. That’s because you’re snapping the position of the object (that little symbol in the centre) to a grid, which is a specific position (the line).

There are two aspects to solving this:

Scene root position

When viewing a scene (like your player), if you click on the root node (at the top of Scene) you’ll see a red cross indicating the root position. For side-view games, we want this on the bottom/feet of the object.

  1. Set the root position of your objects to their feet/bottom to make it easy to snap to floors. With top-level object selected, you should see the root (red cross) on the red line (x-axis). See short video here. With top-level object selected, you should see the root (red cross) on the red line
  2. Or if they’re just a sprite, use the Offset setting.

World position on grid

We need to align our grid with our world so it positions objects correctly.

  1. From the snap settings, Configure Snap and adjust the offset to put the grid line in the middle of your tiles. configure snap to middle
  2. Or you could also adjust the position of your TileMap to be on the grid instead.