2
\$\begingroup\$

When I'm placing objects on tiles in my TileMap, they snap to positions that aren't on my tile's grid. I drag my object to the middle of the grid square, but it keeps snapping to the corners.

I'm talking about placing in the editor, not at runtime.

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

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).

For reference, these are the snap settings:

Godot 4.0.3 snap settings

There are two aspects to solving this: your object's root and your grid/world settings.

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.
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .