Heyo, recently I’ve been wanting to create a placement system with stacking and all that good stuff. I’ve tried using math.clamp, not what I want. I’ve already set the plot boundaries but was just wondering how to correctly align the model in the grid squares because I am using a universal grid.
I’ve taken a look at both articles,
but neither helped in my situation so I’ve come here asking for an extra helping hand.
This is what I’ve tried:
local CanvSize = (Vector3.new(self.Plot.Size.X, self.Plot.Size.Y, self.Plot.Size.Z))/2
local CanvPos = self.Plot.CFrame:ToObjectSpace(CFrame.new(self.Plot.Position.X, self.Plot.Position.Y,self.Plot.Position.Z))
local FixedPos = CanvPos:ToWorldSpace(CFrame.new((CanvSize * self.GridSize)))
local X = math.floor(position.X/FixedPos.X + .5) * (CanvSize.X/self.GridSize) - CanvPos.X
local Z = math.floor(position.Z/FixedPos.Z + .5) * (CanvSize.Z/self.GridSize) - CanvPos.Z
print(X, Z)
local Y = math.floor(position.Y/self.GridSize + 0.5) * self.GridSize + model.PrimaryPart.Size.Y/2
I’ve tried using:
local X = math.floor(position.X/self.GridSize + 0.1) * self.GridSize
local Y = math.floor(position.Y/self.GridSize + 0.5) * self.GridSize + model.PrimaryPart.Size.Y/2
local Z = math.floor(position.Z/self.GridSize + 0.1) * self.GridSize
but that led me with this:
https://gyazo.com/c5a2dd0c67eb6c52568f7b34c6ec9dff
If anyone knows how to properly calculate the grid, thank you!