Download

How can I divide a floor into a grid

Hey Guys, Is there a way to convert a plane into a snapping grid. I want to make something like the ground surface used in strategy games(clash of clans, etc), where we can snap the objects to particular grids.

Thank You

Can you be a bit more specific? (:

Do you want to cut ONE plane into several smaller ones?
Do you want to know how to align planes to a grid by hand?

Do you want to know how to code a selfbuilding grid? AND
Do you want to know how to snap spawned actors to this grid?

Maybe the first one. The end result I want is the ability to place my static mesh or buildings for example into the map and it should snap to a grid. Just like clash of clans where the player can move the structures and it snaps to the grid.

Thanks

Then it is runtime. Uff, first you will need to define a size of your grid and of each grid tile.
For example one tile is 100x100 Units. A map could have 10x10 Tiles.

If you spawn the first tile at (0,0,0) and this is the middle, you would have a tile on (100,0,0), one on
(0,100,0), (100,100,0), (-100,0,0), (0,-100,0), (-100,-100,0) and so on. Either you place them by hand,
or you write yourself a small function with 2 for loops that spawns all the tiles for you.

Then you could make it easy for you to snap the buildings at runtime, because you could LineTrace
the grid and if you hit one of these tiles, you can just set the location of the building to the location
of the tile. Moving your mouse or what ever to the next tile will automatically snap it to
the new one.

“Tile” class here is just a blueprint that has a StaticMeshComponent with a 100x100x1 Box in it.

Then you can trace (Start and End depends on how you trace. There are also trace nodes directly for mobile touch etc)
and check if you hit a TileActor. Then use the Location. Since you placed them in a grid, the location will snap.

Thank You for the answer. I’ll try this and will let you know.

good tutorial, any way to line trace the grid location? I think I’m slowly answering my own question by manipulating the xy values

In the picture, your first for loop (the lower one) is not executed. Maybe you didn’t notice this.

You want to trace each tile or the whole floor? You can trace a tile if you make sure that the tile blocks the line trace (either by Object or by channel)
and cast the HitActor to the Tile Actor Class. If it is not the Tile or a Child class of the tile, the cast will fail.

If you just want to trace the floor, you should be good with just getting the Line Trace to be blocked by the tiles. (Collision settings of the Tile!)