Problem here: Part is being placed 2 studs away from the grid,
but if I move the baseplate back 2 studs in studio, and go again,
It’s in line. Now I know I could just do that and there is then no problem. However, if I have 15-16 of these plots scattered around a map, I don’t want to have to go each one and make sure they are all on the same ‘world’ grid. I want the game to base the walls positioning (and thus future items positions) on the base parts position, and not just a world position. I’ve always used base.Position and base.Size, base.CFrame for everything so I don’t know why when I move the bases position it alters the position of these walls.
RoundModule
local round = {}
function roundNumber(number, to)
to = to or 1
return math.floor(number/to + 0.5) * to
end
function round:Vector(vector, unit, yValue)
return Vector3.new(roundNumber(vector.X, unit), yValue, roundNumber(vector.Z, unit))
end
return round
Positioning
local renderPosition = {}
local round = require(script.Parent.Round)
local clampMouse = require(script.Parent.ClampMouse)
local gridSize = 5
function renderPosition:Render(playersPlot, mouseP, pole, lowerX, upperX, lowerZ, upperZ)
local mouseClampedP = clampMouse:Clamp(mouseP, lowerX, upperX, lowerZ, upperZ)
pole.CFrame = CFrame.new(
round:Vector(mouseClampedP + Vector3.new(0, pole.Size.X/2, 0),
gridSize,
playersPlot.Base.Position.Y + (pole.Size.X/2) + 0.05)
)*CFrame.Angles(0, 0, math.rad(90))
end
return renderPosition
MouseClamp
local clampMouse = {}
function clampMouse:Clamp(mouseP, lowerX, upperX, lowerZ, upperZ)
local mouseClampedP = Vector3.new(
math.clamp(mouseP.X, lowerX, upperX),
mouseP.Y,
math.clamp(mouseP.Z, lowerZ, upperZ)
)
return mouseClampedP
end
return clampMouse
If I am missing anything let me know!