Cheers, I would like to create simulator where the player can customize his house. So he shoukd be able to create walls, floors, and any kind of forniture. So the play select a wall for example from his inventory and can place it in the world, clipped to the ground and grid adjusted. Pretty much like in “The Sims”.
Whats the way to go? Where should I start?
Thanks in advance!
So, generally, for aligning things to grids… Idk, there might be plugins that do it for you or something, but the math is not super complicated either.
For the sake of the example, let’s assume a 1-dimensional world (so we’re trying to place an object somewhere on a line).
So, say the user clicks at position x on our line, we want to take x and align it to our grid. For example, if our grid cells are 2 meters wide, and if x is 5.3, we want to change it to 6.
The way to do that is pretty simple. Divide x by the size of the grid cells, round that number to the nearest integer, and then multiply by the grid cell size.
Oh, and here is some documentation about raycasting from the screen, which is one way to figure out where the user is hovering their mouse. This page shows how to get a to- and from-point for a ray, and then you’d use ordinary raycasting (see further up on the same page) to find the objects that the ray is intersecting with. It’s also possible to use a collision mask to make the raycast ignore certain objects.