Clearly I need to move it along the new axis of the baseplate. So after spending a while spent looking through all the F3X, Build V4 and QCmdUtl plugins… I have absolutely no idea how they move objects on local axis.
Here’s a code snippet of how I snap the objects to the grid.
local function BaseFourRound(Mouse,Object)
local Position = Mouse.Hit.p
local TopRight = CFrame.new(Object.CFrame.X,0,Object.CFrame.Z) * CFrame.new(Vector3.new(Object.Size.X/2,0,Object.Size.Z/2)-Vector3.new(2,0,2))
local XPosition,YPosition,ZPosition;
local Count = 0
for i = 1,(Object.Size.X/4)-1 do
local CurrentPosition = TopRight * CFrame.new((-i*4) * Vector3.new(1, 0, 0))
local UnitPoint = CurrentPosition.p.X - Position.X
if UnitPoint >= -2 and UnitPoint <= 2 then
XPosition = -i*4
break;
end
Count = Count + 1
if i == (Object.Size.X/4)-1 and Position.X < UnitPoint then
XPosition = -i*4
end
end
I’m struggling to understand what exactly you’re doing in your code, but I’ll assume you’re aligning it from the “top right” corner of the baseplate, correct me if I’m wrong.
Considering it seems like you’re doing everything in object space, should you not need to just multiply the TopRight variable by the rotation of the base? (This is assuming that you align by the top right corner)
I did it by converting the mouse position into object space relative to a corner of the base-plate, meaning it’s retaining rotation. Then I forced boundaries on it and simply multiplied by the corner CFrame, since it’s relative to it to begin with, to convert it to world space for the positioning of the object.
At this point it shouldn’t be too difficult to edit the code to include snapping or anything you’d like really, so I’ll leave the code here. Side-note, this probably isn’t the cleanest or most efficient code but you’ll probably be able to salvage it.
function Align(mouse, obj)
local pos = mouse.Hit.p
local bounds = base.Size
local halfObjectSize = obj.Size * 0.5
local corner = base.CFrame * CFrame.new(bounds * 0.5)
local relativeCF = corner:toObjectSpace(CFrame.new(pos))
relativeCF = CFrame.new(
math.clamp(relativeCF.X, -bounds.X + halfObjectSize.X, -halfObjectSize.X),
bounds.Y * 0.5,
math.clamp(relativeCF.Z, -bounds.Z + halfObjectSize.Z, -halfObjectSize.Z)
)
obj.CFrame = corner * relativeCF
end