function onMove(face, distance)
local step = distance - lastDistance
if step > 2 then
local move = Vector3.FromNormalId(face) * step
lastDistance = distance
selected.CFrame = selected.CFrame * CFrame.new(move)
end
end
local function SnapToGrid(val, gridSize)
return math.round(val / gridSize) * gridSize
end
Additionally, to fix this buggy movement you can do this.
selected.CFrame = originCF * CFrame.new(move)
Working example:
local handles = script.Parent
local selected = workspace.Part
local originCF = CFrame.identity
local moveIncrement = 1
local function SnapToGrid(val, gridSize)
return math.round(val / gridSize) * gridSize
end
local function OnDragMove(face, distance)
local step = SnapToGrid(distance, moveIncrement)
local direction = Vector3.FromNormalId(face)
local move = direction * step
selected.CFrame = originCF * CFrame.new(move)
end
local function OnDragBegin()
originCF = selected.CFrame
end
handles.MouseDrag:Connect(OnDragMove)
handles.MouseButton1Down:Connect(OnDragBegin)