#grid placement help
201 messages · Page 1 of 1 (latest)
you mean like this ?
no like this wait
you mean like minecraft build syste ?
system
yeah smt like that
i mean i already made it
im just facing some issues
sorry to say that but this is bad system
i made one
you need Collision system
its not mine
i have already collisions
system
i need new grid system
bc this one in the video is not smooth
There must be a system that determines the location of the mouse on the
block
to be built on,
ill continue talking with u after im home alr?
and then knows in which direction a distance of half the length of the block must be added.
yes we can fix this
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
no i want it 4 grid system
i made it already the problem that the preview block is sometimes moved inside another block which doesnt make the build system smooth
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
u mean mouse.Targer?
yes
Mouse.Target
just detect the object
then make it snap to the axis using the help of both Mouse.Target and Mouse.Hit
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)
If only I had more experience with this snapping stuff
I mean
something like this
or Mouse.Target.Name == the block name
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
Honestly you should use math.clamp to make sure it doesn't make some weird clipping
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
!!
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
i did but no difference
ss of code?
2 sides doesnt work
because you're only detecting the y axis
/ clamping the y axis only
But the question is
wait do i need to clamp Y?
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
ight ill try it out
@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
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
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
?
ill try
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
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
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
gn
@woeful charm you domt need snaping function
you just need to know wher is the mouse for the target
how
use this
what this
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
ill try it
this is my system use grid and its customisable
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.
bro dont use this just use ```lua
mouse.Hit.Position - targ.Position
or something better
yes then move block to newPositon]
is it work ?
you can also use ```lua
mouse.target.CFrame:pointToObjectSpace(mouse.Hit.Position)
hmmmm
Let me think of something simpler and more practical.
does this happen in ur game
@woeful charm did Do you use blocks of identical dimensions?
no its work perfect
ye local objSize = Vector3.new(gridSize, gridSize, gridSize)
wanna check the game?
like edit
on it
i need to check all the script
to see where is the error
i will remake it for you
or i will make another one simple
You did not answer
its only one script
(for test)
i said ye
whats ur user
do you want to rotate it ?
ye
ok then we cant use mouse.target.CFrame:pointToObjectSpace(mouse.Hit.Position)
then
alr
** You are now Level 9! **
you can
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)
yk whats the problem?
yes
You checked 3 out of 6 directions.
you checked (+x , +y , +z)
but you dont checked (-x , -y , -z)
ley me fix it
oh yeah
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
I know but then you'd have to get what it's closest to
it doesn't get the specified axis
but I should stay out of this maybe because I haven't made a snapping function before
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
This method works
but
if you rotate the block
