In-game Building system -> How to prevent "stacking" built assets?

Hello guys,
Sorry for bad title, but I have no idea how to form it properly.

I am making a Fortnite-alike building system in my game, and I have a question, how can I prevent the situation shown in the attachment.

Info about building assets:

  • Y-axis is always the same
  • Each asset is a square of same size

Also, I hope you understand what I mean on the image. If any questions, ask me.

If you have a grid you have to quantify positions to that grid.

When you have a grid, you keep track of what is in each cell using some kind of collection, such as:

  • a Dictionary with a positional key

  • a 2-dimensional array.

Then you would need a Dictionary with a positional key rather than a 2-dimensional array.

Quantification still applies. That applies to any grid game, 1D, 2D, 3D or even 4D if that’s possible.

If you’re looking to snap these items together like in fornite then there’s a specific technique you can use involving putting empty gameobjects that act like nodes onto each side of your gameobject, this same technique I think could be used in 2D.

Be warned though it is a fairly deep topic you’re asking about.

1 Like

For the game I created not long ago, I did a socket design very similar to what’s posted by @Lethn above.

A building block would have a bunch of empty child gameobjects which would act as a socket. The sockets would be positioned prior to run time.

Each socket had a script on it that contained a list of buildingblocks that it would accept.

I then just used a raycast from the players camera forward position to check whether sockets were available or not and would place a preview block if so.

3 Likes