#Help with grid system

5 messages · Page 1 of 1 (latest)

latent zephyr
#

The block wont move along the negative of the X axis, but works fine with every other axis.

Grid system code:

local grid = .5

function Snap(Position, blockSize) 
    
    
    local posX = math.round((blockSize.X / 2) + Position.X)
    local posY = math.round((blockSize.Y / 2) + Position.Y)
    local posZ = math.round((blockSize.Z / 2) + Position.Z)
        
    return Vector3.new(posX, posY, posZ)
end

uis.InputBegan:Connect(function(input)
    
    if buildingEnabled.Value == true then
        if input.UserInputType == Enum.UserInputType.MouseButton1 then
            --local pos = mouse.Hit.Position
            local block = game.ReplicatedStorage.Blocks:WaitForChild(script.CurrentBlock.Value)
            local pos = Snap(mouse.hit.Position, block.Size)
            
            if block ~= nil then
                local a = script.TemplateBlock.Value
                local re = block:Clone()
                re.Parent = game.Workspace
                re.Position = pos
                re.Orientation = a.Orientation
            end

        end
    end
    
end)

toxic sparrowBOT
#

studio** You are now Level 3! **studio

humble ledge
#
function Snap(Position, blockSize) 
    local posX = math.round(Position.X / grid) * grid + (blockSize.X / 2)
    local posY = math.round((blockSize.Y / 2) + Position.Y)
    local posZ = math.round((blockSize.Z / 2) + Position.Z)
        
    return Vector3.new(posX, posY, posZ)
end
latent zephyr
median acorn
#

why do you set the Z position diffrent from the X position?