I need help with a block placement system

Hello. Recently I have been creating a game where you build blocks with a color and a size value. The problem is, my block positioning system doesn’t account for uneven values. Vector3(1,1,1) works, but not Vector3(1,3,7) How could I incorporate uneven values too?

What I want to happen:
image

What happens:

The code that I think might be causing this:

        local xDif = 0
		local yDif = 0
		local zDif = 0

		local x = 0
		local y = 0
		local z = 0

		if surface == Enum.NormalId.Top then
			warn("top")
			yDif = trackingPart.Size.Y
		elseif surface == Enum.NormalId.Bottom then
			warn("bottom")
			yDif = -trackingPart.Size.Y
		elseif surface == Enum.NormalId.Front then
			warn("front")
			zDif = -trackingPart.Size.X
		elseif surface == Enum.NormalId.Back then
			warn("back")
			zDif = trackingPart.Size.X
		elseif surface == Enum.NormalId.Right then
			warn("right")
			xDif = trackingPart.Size.Z
		elseif surface == Enum.NormalId.Left then
			warn("left")
			xDif = -trackingPart.Size.Z 
-- I have to make each one of these values change based on the parts size but I have no clue how to
		end
		
		local X = trackingPart.Size.X
		local Y = trackingPart.Size.Y 
		local Z = trackingPart.Size.Z

		local round = math.round(X + Y + Z / 3) / 6
		
		if target.Name == "Block" then
			x = math.round(target.Position.X) + xDif
			y = math.round(target.Position.Y) + yDif
			z = math.round(target.Position.Z) + zDif
		else
			x = math.round(Mouse.Hit.Position.X/round)*round
			y = math.round(target.Position.Y/6) / 6 + yDif
			z = math.round(Mouse.Hit.Position.Z/round)*round
		end

Any help is appreciated.

1 Like

Hello, this still isn’t solved.

1 Like

You’re using the same rounding factor ‘round’ for all three dimsensions. Works fine for blocks with equal dimensions but not for blocks with uneven dimensions.

Try doing this instead:

local roundX = math.round(trackingPart.Size.X) / 2
local roundY = math.round(trackingPart.Size.Y) / 2
local roundZ = math.round(trackingPart.Size.Z) / 2

if target.Name == "Block" then
    x = math.round(target.Position.X / roundX) * roundX + xDif
    y = math.round(target.Position.Y / roundY) * roundY + yDif
    z = math.round(target.Position.Z / roundZ) * roundZ + zDif
else
    x = math.round(Mouse.Hit.Position.X / roundX) * roundX
    y = math.round(target.Position.Y / roundY) * roundY + yDif
    z = math.round(Mouse.Hit.Position.Z / roundZ) * roundZ
end
2 Likes

Unfornately, that made the block go below the baseplate. But I will try raising its Y by 3x. Edit: It doesn’t work. Uneven part sizes still are spaced too far apart. I want them to connect. Play the game here and place a default size block then set the size value to 1,3,7 and try connecting it to the block and you’ll see what I mean.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.