#grid placement help

201 messages · Page 1 of 1 (latest)

woeful charm
#

I want a better grid system As you can see the preview block is sometimes placed inside another block I need a solution for this issue make it very difficult for the preview block to go inside another block

#

Notice that the preview block indicates where the mouse block is positioned

cobalt fulcrum
woeful charm
#

no like this wait

cobalt fulcrum
#

system

woeful charm
#

i mean i already made it

#

im just facing some issues

cobalt fulcrum
#

i made one

#

you need Collision system

woeful charm
#

i have already collisions

#

system

#

i need new grid system

#

bc this one in the video is not smooth

cobalt fulcrum
#

There must be a system that determines the location of the mouse on the

#

block

#

to be built on,

woeful charm
#

ill continue talking with u after im home alr?

cobalt fulcrum
#

and then knows in which direction a distance of half the length of the block must be added.

cobalt fulcrum
#

if you want to make it blocks with same axis siez

#

this will make it

#

easy

#

you just need to know what is the mouse direction relative to the block

woeful charm
#

i made it already the problem that the preview block is sometimes moved inside another block which doesnt make the build system smooth

woeful charm
clever valley
#

Either I have memory loss or there was a function that lets you know what instance your mouse is hovering over

#

If this isn't something that exists then I would use (I haven't made such snapping functions before) but I would use clamping or follow a pattern for the positions of each block

clever valley
#

Mouse.Target

#

just detect the object

#

then make it snap to the axis using the help of both Mouse.Target and Mouse.Hit

woeful charm
#

like this

#
local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local gridSize = 4 
function clampToGrid(position, gridSize)
    local x = math.floor(position.X / gridSize) * gridSize
    local y = math.floor(position.Y / gridSize) * gridSize
    local z = math.floor(position.Z / gridSize) * gridSize
    return Vector3.new(x, y, z)
end

tool.Activated:Connect(function()
    local target = mouse.Target
    if target then
        local mousePosition = mouse.Hit.p
        local clampedPosition = clampToGrid(mousePosition, gridSize)

        local newPart = Instance.new("Part")
        newPart.Size = Vector3.new(4, 4, 4)
        newPart.Position = clampedPosition
        newPart.Anchored = true
        newPart.Parent = workspace

        print("Placed a block at: " .. tostring(clampedPosition))
    else
        print("No valid target to place a block on.")
    end
end)

clever valley
#

If only I had more experience with this snapping stuff

#

I mean

#

something like this

#

just make sure it isn't nil and it is the block that you want it to snap to

#

I might attempt to make a snapping function sometime soon

clever valley
woeful charm
#

alr ill try

#

sadly didnt work

#
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local gridSize = 4
mouse.Button1Down:Connect(function()
    local mousePosition = mouse.Hit.Position
    local target = mouse.Target

    if target and target:IsA("BasePart") then
        local gridX = math.round(mousePosition.X / gridSize) * gridSize
        local gridY = math.round(mousePosition.Y / gridSize) * gridSize
        local gridZ = math.round(mousePosition.Z / gridSize) * gridSize

        gridY = math.clamp(gridY, target.Position.Y, target.Position.Y + target.Size.Y)

        local block = Instance.new("Part")
        block.Size = Vector3.new(4, 4, 4)
        block.Position = Vector3.new(gridX, gridY, gridZ)
        block.Anchored = true
        block.Parent = workspace
    end
end)
#

to be honest i didnt expect it to be that hard im trying so hard to figure out the issue but none of them worked

clever valley
#

I'd have to dive in myself sometime and make a snap function

#

but you should keep the math.clamp honestly

#

it'll prevent those annoying clipping parts

woeful charm
#

i did but no difference

clever valley
#

you must've done something wrong

#

send ss

woeful charm
#

ss of code?

clever valley
#

No

#

when you playtest

woeful charm
#

2 sides doesnt work

clever valley
#

/ clamping the y axis only

#

But the question is

woeful charm
#

ill try clamp the others

#

to

clever valley
#

yea

#

but is there a way to get which way the face of a part is looking at

woeful charm
#

wait do i need to clamp Y?

clever valley
#

I mean yeah, realistically all of them

#

but the thing is

#

you need to also detect from where you are hovering over

#

which side of the cube

#

like

#

let's say you made a variable for xyz

#

then you make it so the faces that are facing the x axis

#

= the x variable

#
if x then 

    -- clamp the x

end
#

it feels like I'm over complicating it

#

couldn't you make like a border around the cube

woeful charm
#

ight ill try it out

clever valley
#

@woeful charm

#

Detect which one it's hovering over?

#

It feels like there are more efficient wayysss

#

but this is what I could think of

woeful charm
#
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local gridSize = 4

mouse.Button1Down:Connect(function()
    local mousePosition = mouse.Hit.Position
    local target = mouse.Target
    
    if target and target:IsA("BasePart") then
        local gridX = math.round(mousePosition.X / gridSize) * gridSize
        local gridY = math.round(mousePosition.Y / gridSize) * gridSize
        local gridZ = math.round(mousePosition.Z / gridSize) * gridSize

        if mousePosition.X > target.Position.X - target.Size.X / 2 and mousePosition.X < target.Position.X + target.Size.X / 2 then
            gridY = target.Position.Y
            gridZ = math.clamp(gridZ, target.Position.Z - target.Size.Z / 2, target.Position.Z + target.Size.Z / 2)
        end
        
        if mousePosition.Y > target.Position.Y - target.Size.Y / 2 and mousePosition.Y < target.Position.Y + target.Size.Y / 2 then
            gridX = math.clamp(gridX, target.Position.X - target.Size.X / 2, target.Position.X + target.Size.X / 2)
            gridZ = math.clamp(gridZ, target.Position.Z - target.Size.Z / 2, target.Position.Z + target.Size.Z / 2)
        end
        
        if mousePosition.Z > target.Position.Z - target.Size.Z / 2 and mousePosition.Z < target.Position.Z + target.Size.Z / 2 then
            gridY = target.Position.Y
            gridX = math.clamp(gridX, target.Position.X - target.Size.X / 2, target.Position.X + target.Size.X / 2)
        end

        gridY = math.clamp(gridY, target.Position.Y, target.Position.Y + target.Size.Y)

        local block = Instance.new("Part")
        block.Size = Vector3.new(4, 4, 4)
        block.Position = Vector3.new(gridX, gridY, gridZ)
        block.Anchored = true
        block.Parent = workspace
    end
end)

#

i added stuff

#

it still does the same

#

2 sides doesnt work

#

it is getting too complicated

clever valley
#
if Mouse.Target.Name == "Y1" or "Y2" then

    -- Clamp Y

elseif Mouse.Target.Name == "X1" or "X2" then

    -- Clamp X

elseif Mouse.Target.Name == "Z1" or "Z2" then

    -- Clamp Z

end
#

?

woeful charm
#

ill try

clever valley
#

Just make sure to do the border

#

just make the base a tad bit smaller

#

In reality you can just have the cube itself be the borders

#

but up to you how you do this

woeful charm
#

i did this ```lua
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local gridSize = 4

mouse.Button1Down:Connect(function()
local mousePosition = mouse.Hit.Position
local target = mouse.Target

if target and target:IsA("BasePart") then
    local targetSize = target.Size / 2
    local targetPosition = target.Position

    local gridX = math.round(mousePosition.X / gridSize) * gridSize
    local gridY = math.round(mousePosition.Y / gridSize) * gridSize
    local gridZ = math.round(mousePosition.Z / gridSize) * gridSize


    if math.abs(mousePosition.X - targetPosition.X) < targetSize.X then
        gridY = targetPosition.Y
        gridZ = math.clamp(gridZ, targetPosition.Z - targetSize.Z, targetPosition.Z + targetSize.Z)
    end

    if math.abs(mousePosition.Y - targetPosition.Y) < targetSize.Y then
        gridX = math.clamp(gridX, targetPosition.X - targetSize.X, targetPosition.X + targetSize.X)
        gridZ = math.clamp(gridZ, targetPosition.Z - targetSize.Z, targetPosition.Z + targetSize.Z)
    end

    if math.abs(mousePosition.Z - targetPosition.Z) < targetSize.Z then
        gridY = targetPosition.Y
        gridX = math.clamp(gridX, targetPosition.X - targetSize.X, targetPosition.X + targetSize.X)
    end

    gridY = math.clamp(gridY, targetPosition.Y, targetPosition.Y + targetSize.Y)

    local block = Instance.new("Part")
    block.Size = Vector3.new(4, 4, 4)
    block.Position = Vector3.new(gridX, gridY, gridZ)
    block.Anchored = true
    block.Parent = workspace
end

end)

it work from all sides now but it is a bit too buggy
#

well except Y

#

@clever valley maybe try the script and check whats wrong with it?

#

in studio

clever valley
#

I'm about to sleep

#

I'm no good during late times trust me 😭

#

but dm me tmrw and add me to your project ig then we'll figure it out together

woeful charm
#

alr its fine we can continue tmr

#

gn

clever valley
#

gn

cobalt fulcrum
#

@woeful charm you domt need snaping function

#

you just need to know wher is the mouse for the target

woeful charm
#

how

cobalt fulcrum
#

use this

woeful charm
#

what this

cobalt fulcrum
#
difference = mouse.Hit.Position - targ.Position
#
local function setPos() -- Calculate the direction and magnitude of displacement
    if distX > 0 and math.abs(distX) >= targSize.X then
        scaledPosition = Vector3.new(
            mouse.Hit.Position.X + (objSize.X),
            math.round(mouse.Hit.Y/gridSize)*gridSize,
            math.round(mouse.Hit.Z/gridSize)*gridSize
        )
    elseif distX < 0 and math.abs(distX) >= targSize.X then
        scaledPosition = Vector3.new(
            mouse.Hit.Position.X - (objSize.X),
            math.round(mouse.Hit.Y/gridSize)*gridSize,
            math.round(mouse.Hit.Z/gridSize)*gridSize
        )
    elseif distY > 0 and math.abs(distY) >= targSize.Y then
        scaledPosition = Vector3.new(
            math.round(mouse.Hit.X/gridSize)*gridSize,
            mouse.Hit.Position.Y + (objSize.Y),
            math.round(mouse.Hit.Z/gridSize)*gridSize
        )
    elseif distY < 0 and math.abs(distY) >= targSize.Y then
        scaledPosition = Vector3.new(
            math.round(mouse.Hit.X/gridSize)*gridSize,
            mouse.Hit.Position.Y - (objSize.Y),
            math.round(mouse.Hit.Z/gridSize)*gridSize
        )
    elseif distZ > 0 and math.abs(distZ) >= targSize.Z then
        scaledPosition = Vector3.new(
            math.round(mouse.Hit.X/gridSize)*gridSize,
            math.round(mouse.Hit.Y/gridSize)*gridSize,
            mouse.Hit.Position.Z + (objSize.Z)
        )
    elseif distZ < 0 and math.abs(distZ) >= targSize.Z then
        scaledPosition = Vector3.new(
            math.round(mouse.Hit.X/gridSize)*gridSize,
            math.round(mouse.Hit.Y/gridSize)*gridSize,
            mouse.Hit.Position.Z - (objSize.Z)
        )
    end
end
woeful charm
#

ill try it

cobalt fulcrum
#

You can change the size of the blocks, make different dimensions, and change the size of the grid. and rotate it

#

but this would be more complicated than having the blocks be of equal dimensions.

cobalt fulcrum
# clever valley

bro dont use this just use ```lua
mouse.Hit.Position - targ.Position

#

or something better

woeful charm
#

i did this

#

i cant send script

#

like thsi

cobalt fulcrum
#

is it work ?

#

you can also use ```lua
mouse.target.CFrame:pointToObjectSpace(mouse.Hit.Position)

woeful charm
#

not able to add on this side

cobalt fulcrum
#

Let me think of something simpler and more practical.

woeful charm
cobalt fulcrum
#

@woeful charm did Do you use blocks of identical dimensions?

cobalt fulcrum
woeful charm
#

ye local objSize = Vector3.new(gridSize, gridSize, gridSize)

#

wanna check the game?

#

like edit

#

on it

cobalt fulcrum
#

to see where is the error

#

i will remake it for you

#

or i will make another one simple

woeful charm
#

(for test)

#

i said ye

#

whats ur user

cobalt fulcrum
woeful charm
#

ye

cobalt fulcrum
# woeful charm ye

ok then we cant use mouse.target.CFrame:pointToObjectSpace(mouse.Hit.Position)

woeful charm
#

then

cobalt fulcrum
#

show me your script

#

i will fix it

woeful charm
#

alr

rotund elbowBOT
#

studio** You are now Level 9! **studio

woeful charm
#

i cant

#

its too big

#

wait

cobalt fulcrum
woeful charm
#
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local gridSize = 4
local objSize = Vector3.new(gridSize, gridSize, gridSize)

local function setPos()
    local difference = mouse.Hit.Position - mouse.Target.Position
    local scaledPosition = Vector3.new(
        math.round(mouse.Hit.X / gridSize) * gridSize,
        math.round(mouse.Hit.Y / gridSize) * gridSize,
        math.round(mouse.Hit.Z / gridSize) * gridSize
    )

    if math.abs(difference.X) >= objSize.X then
        scaledPosition = Vector3.new(
            mouse.Hit.Position.X + math.sign(difference.X) * objSize.X,
            math.round(mouse.Hit.Y / gridSize) * gridSize,
            math.round(mouse.Hit.Z / gridSize) * gridSize
        )
    elseif math.abs(difference.Y) >= objSize.Y then
        scaledPosition = Vector3.new(
            math.round(mouse.Hit.X / gridSize) * gridSize,
            mouse.Hit.Position.Y + math.sign(difference.Y) * objSize.Y,
            math.round(mouse.Hit.Z / gridSize) * gridSize
        )
    elseif math.abs(difference.Z) >= objSize.Z then
        scaledPosition = Vector3.new(
            math.round(mouse.Hit.X / gridSize) * gridSize,
            math.round(mouse.Hit.Y / gridSize) * gridSize,
            mouse.Hit.Position.Z + math.sign(difference.Z) * objSize.Z
        )
    end

    return scaledPosition
end

mouse.Button1Down:Connect(function()
    if mouse.Target then
        local newPosition = setPos()
        if newPosition then
            local block = Instance.new("Part")
            block.Size = objSize
            block.Position = newPosition
            block.Anchored = true
            block.Parent = workspace
        end
    end
end)
cobalt fulcrum
#

its not big do you want to see big one troll

woeful charm
#

anyway

cobalt fulcrum
cobalt fulcrum
#

You checked 3 out of 6 directions.

#

you checked (+x , +y , +z)
but you dont checked (-x , -y , -z)

#

ley me fix it

woeful charm
#

alr

#

i made it

#

but i found some bugs

#

i think ill try urs

#

are u done

cobalt fulcrum
#

i forget sorry

#

this is the script

#
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local gridSize = 4

local function setPos()
    local newPositon
    local target = mouse.Target

    if target then
        local difference = mouse.Hit.Position - target.Position

        if math.abs(difference.X) >= gridSize / 2 then
            if difference.X > 0 then
                newPositon = target.Position + Vector3.new(gridSize, 0, 0)
            else
                newPositon = target.Position - Vector3.new(gridSize, 0, 0)
            end
        elseif math.abs(difference.Y) >= gridSize / 2 then
            if difference.Y > 0 then
                newPositon = target.Position + Vector3.new(0, gridSize, 0)
            else
                newPositon = target.Position - Vector3.new(0, gridSize, 0)
            end
        elseif math.abs(difference.Z) >= gridSize / 2 then
            if difference.Z > 0 then
                newPositon = target.Position + Vector3.new(0, 0, gridSize)
            else
                newPositon = target.Position - Vector3.new(0, 0, gridSize)
            end
        end
    end

    return newPositon
end

mouse.Button1Down:Connect(function()
    local newPos = setPos()
    if newPos then
        local block = Instance.new("Part")
        block.Size = Vector3.new(gridSize, gridSize, gridSize)
        block.Position = newPos
        block.Anchored = true
        block.Parent = workspace
    end
end)```
#

you can idet it

clever valley
#

it doesn't get the specified axis

#

but I should stay out of this maybe because I haven't made a snapping function before

woeful charm
#

this method is very similar to ```lua
elseif Target.Parent.Name == "BuildContainer" then
OutOfBounds = false
if Mouse.TargetSurface == Enum.NormalId.Front then
RB.Position = Target.Position + Vector3.new(0,0,-3.5)
elseif Mouse.TargetSurface == Enum.NormalId.Back then
RB.Position = Target.Position + Vector3.new(0,0,3.5)
elseif Mouse.TargetSurface == Enum.NormalId.Left then
RB.Position = Target.Position + Vector3.new(-3.5,0,0)
elseif Mouse.TargetSurface == Enum.NormalId.Right then
RB.Position = Target.Position + Vector3.new(3.5,0,0)
elseif Mouse.TargetSurface == Enum.NormalId.Top then
RB.Position = Target.Position + Vector3.new(0,3.5,0)
elseif Mouse.TargetSurface == Enum.NormalId.Bottom then
RB.Position = Target.Position + Vector3.new(0,-3.5,0)
end
RB.Parent = BuildSpace

#

@cobalt fulcrum

#

right?

#

but this system is not rly good

#

it works tho

#

but i dont think it is recommended i think

cobalt fulcrum
#

but

#

if you rotate the block