Caulculating vector location for objects to spawn next to each other

Hello everyone!

I’m creating a build system for learning purposes. Currently I’m making the “foundation” parts or to put more precisely the wooden base of the house. It’s a simple mesh with exact dimensions of 2 meters by 2 meters and .50 meters on the z. I’ve already set up the spawning part. But they do not stand next to each other properly. I’m ray tracing from the player to where he is aiming, floor X, Y and ceil Z of the hit location and then feed it to the spawn function but aparently it doesn’t work properly. there’s still some space left between them. What am I missing?

How are you snapping your coordinates? Simply flooring the trace’s hit location will “floor” to the next lowest cm. You need to round to the size of your building blocks, probably 2 meters.

To do that you divide by 2 meters (200 cm), floor, then multiply again.

E.g. Your trace hits at (1005, 505, 95).

Your snapped coordinates then would be

X = floor(1005 / 200) * 200 = 1000
Y = floor(505 / 200) * 200 = 500
Z = ceil(95 / 50) * 50 = 100

Oh yes, it worked! Thanks for the help :slight_smile: