How do I set up a grid snap like RTS games?

I am interested in setting up a grip snap feature with my game (which is an RTS). Using the classic 2x2 and 3x3 tile format, I want to make it so that when you snap it to a grid making it more organized. Any suggestions on hoe to do it using Blueprints? Thank you.


in the editor or within the game?

Here’s a macro I use to snap individual axes in my project:

Within the game.

Ill try this and let you know what happens. Thank you.

Works like a charm.

How does this work? I use this macro on the map, I create a grid, or use it on the objects that I wanto to move around? how do I use this? I’m trying to creating a snaping mechanics in a drag and drop game, like Clash Of Clans, and then I need to snap the object on certains locations, I trying to do a test with a simple Cube actor, but it is moving freely, not snaping on the ground

This macro takes a number and snaps it to the nearest multiple of another number. So, with a grid size of 50, the number 164, passed through this macro, will output 150, and 189 will output 200. If you pass, for example, the coordinates of your cursor’s screen to world position, you can use the output to set the location of an object in the world to the nearest coords that are a multiple of your grid size.

You’ll have to figure the rest out on your own.

I have figured out what I needed to do, thanks. In my project I move a box via cursor to set it in a specific location, thanks to this, and based on other examples I found it rounds based on the grid I dragging the box. Now I just need to figure out how I make the box snap to Z when it finds a collision, and the back to the lowest Z when out of collision

Hey I’ve got something similar going on, did you figure out how to snap to Z upon collision?

Just FYI, I found there is a specific function for this:

1 Like