Gdevelop how to summon blocks at mouse with grid

hi Gdevelop how to summon blocks with mouse at the nearest grid chunk. i haven’t been able to find anything on it

I suggest Snap to grid extension it may help.

What do you mean by summon? Can you explain further?

like in games where blocks snap to a grid when building

You can watch this if you want :slight_smile:

It has what your after.

But the short of it is…

  • You create a grid with invisible blocks
  • Then you check if mouse cursor is on the block
  • When mouse button is pressed, create Building Block at the invisible blocks position

Something along those lines, the video shows you how

I’m still unsure. But here are 3 general ways. You can remove the mouse and/or trigger once if not needed.

This approach selects the closest Grid object when the mouse button is down.
The cursor would not need to be over an object or inside the collision mask.
image

This would require the cursor to be over or inside the object collision mask.
(pick the nearest is used in case the objects overlap or the person touches multiple objects regardless of whether they overlap)

This would require the cursor x,y to be inside the object collision mask.
(pick the nearest is used in case the objects overlap but since it’s using cursor x and y it should only pick objects that overlap)