How to snap entities to a grid in game

Can you show how you did that? trying to do that but with grid

What are you trying to do? Might be worth creating a new topic for this

A way of customizing the virtual world using already created assets, can used by both players or designers.
I am trying to do so using as an example city builder games or others that use a fixed grid as Clash of Clans. I think it would be a nice feature.
I found an example time ago but was over a 2d plane with 2d assets, so sadly i could not use part of that code because it was also 2d isometric and the way to calculate the places is not the same

Not clear on what you are trying to do here? Do you want to snap 3D objects to a grid?

Yes, clash of clans style of construction

Regardless if you are doing it in 3D/2D/isometric, the logic is pretty much the same. Define a grid area (eg 1x1 unit per grid square) and in the input, work out which grid square it is one/click on based on the world position of the input to the the grid area.

Once you have that, you position the buildings however you like on the grid with that information

It’s what I did for this example: https://playcanvas.com/project/560025/overview/isometric-base-builder

2 Likes