Like it says in the title, I need help with a grid placement system. I want the grid size to be 5 by 5, and I want it to be placed on a floor part.
Thank you so much!
Like it says in the title, I need help with a grid placement system. I want the grid size to be 5 by 5, and I want it to be placed on a floor part.
Thank you so much!
Hey, I’m Hot_Coder and i will be helping you with what you need,
Simply you need to create a function that is similar to math.round() but you will actually make it 5 points rounding not 1 as the math.round() function does
so the function would be something like that
local gridSpacing = 5 -- Its five as you said
function getRoundedPosition(positionToRound)
local posX = positionToRound.X
local posY = positionToRound.Y
local posZ = positionToRound.Z
local roundedX = math.floor((posX / gridSpacing) + 0.5) * gridSpacing
local roundedZ = math.floor((posZ / gridSpacing) + 0.5) * gridSpacing
return Vector3.new(roundedX, posY, roundedZ)
end
local currentPartPosition = Vector3.new(47.56, 10, 22.49)
local roundedPos = getRoundedPosition(currentPartPosition)
print(roundedPos)
--Output 50, 10, 20
And for the Floor Thing you need a function that checks if the Part is being placed on the other part and not outside the part so inside of it heres the function to do that its very simple
local function isPartInside(part1, part2)
local size1 = part1.Size
local size2 = part2.Size
local min1 = part1.Position - size1/2
local max1 = part1.Position + size1/2
local min2 = part2.Position - size2/2
local max2 = part2.Position + size2/2
return (min1.X >= min2.X) and (max1.X <= max2.X) and
(min1.Y >= min2.Y) and (max1.Y <= max2.Y) and
(min1.Z >= min2.Z) and (max1.Z <= max2.Z)
end
Thank you for that, rounding it was the big thing that I did not know how to do.
You are welcome you can now have my post as solution so it could help more people.
Sorry, but how do I make it only work on a certain part(Floor)
You want to make the Part or what ever you are building not be into the ground you want it to be on top of ground ?
So you want to be only be able to place on a specific Part then you would check for mouse.hit (not the best option)
or you would do hard math and get the part’s current X position - the part’s X size divided by 2 and check if the result rounded position is more than that then they are building out of the platform but you will have to do that for all the X and Z axis
On top of a floor piece, Right now it can go on anything.
Read my previous responses and tell me which one you mean
a specific part, I have a floor part that I want it to be placed on
I figured it out, I just set a filter on a few parts, and added a max position.
Thank you for your help, it is working how I want it now.
I have posted the best way to do that i have edited the solution message check it out
Thanks, I have it working, but I will change it to that.
Alright and i think you have to Rotate the part the Right way since its Orientation Sensitive so make sure you do that or else it might not work the way you wanted it to work
Got it, thank you for all your help.
I’m glad that i helped you, You are welcome.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.