Issue placing buildings side by side when rotated

Godot Version

4.7

Question

I already developed a placement system for new constructions for the game I am working on, now I have introduced the possibility to rotate the buildings 10deg at each step instead of 90deg.

Doing that I’m now facing an issue.

I have the following code to move the buildings around before to place them,

var camera: Camera3D = get_viewport().get_camera_3d()
var from: Vector3 = camera.project_ray_origin(get_viewport().get_mouse_position())
var to: Vector3 = from + camera.project_ray_normal(
			get_viewport().get_mouse_position()) * camera.far
var cursor_pos = Plane(Vector3.UP, transform.origin.y).intersects_ray(from, to)
current_spawnable.position = Vector3(round(cursor_pos.x), cursor_pos.y, round(cursor_pos.z))

I used the round() function on cursor_pos.x and cursor_pos.zto have a grid-like alignment which did work fine with objects oriented along the x or z axes, but now I get an unwanted behaviour, the building can’t be placed alongside eachother (of course I’d say), but there is a gap between them, you can see what I mean in the short video below. How can I fix this issue?

The grid produced by rounding is square, so diagonal elements are √2 further apart. I don’t believe there is an easy fix without large design ramifications.

Yes, that is the reason for the gap.

Avoiding to round the x and z coordinates would give the player the possibility to perfectly position the buildings, but it is also hard to place them correctly aligned having a pixel-perfect movement.

I was also thinking to some kind of “snap to existing buildings”, but that could also be tedious for the players because it tries to do something that the players might won’t do.

“Satisfactory” is a game with both “global” grid system similar to your rounding, and local snap-to-building. Maybe some inspiration from that? Not that I know how they do it, and I’m sure it would be easier with square objects like they seem to have.

Make the snap to building a placement option : semi divided homes vs the alley between two houses sort of thing.

Do you want to rotate the tile with building at any angle, or just the building within the tile?

The first will lead you towards solutions that might so help with rectangular two square tiles occupying type of building.

The second means all your buildings and props can be rotated at any angle within a square tile because they are small enough to do so and still fit on the tile sort of thing.

Just off the cuff spitballing while being paid to sweat :sweat_smile: (Canada Day means a day off with pay)

Happy Canuckistan Day to my fellow igloo dwellers!

Cheers !

This also was one of my thought for the snap to other building, I was thinking to put a 3D Marker in the middle of each face where 2 buildings can be placed side by side and match the position of the 2 3D Markers, but that only works if all the buildings have the same size for the sides, thus the cubes.