im making a building game and i made rescale and moving handles with the Handles object, but im trying to make rotate, and its not as expected. im trying to replicate the studio rotate heres my current script:
local handles = script.Parent:WaitForChild("Rotation")
local cframeAtMouseDown
local lastStep = 0
local dragAxis
local dragSign
local faceToAxis = {
[Enum.NormalId.Right] = {axis = Vector3.new(0, 1, 0), sign = 1},
[Enum.NormalId.Left] = {axis = Vector3.new(0, 1, 0), sign = -1},
[Enum.NormalId.Top] = {axis = Vector3.new(1, 0, 0), sign = 1},
[Enum.NormalId.Bottom] = {axis = Vector3.new(1, 0, 0), sign = -1},
[Enum.NormalId.Front] = {axis = Vector3.new(0, 0, 1), sign = 1},
[Enum.NormalId.Back] = {axis = Vector3.new(0, 0, 1), sign = -1},
}
handles.MouseButton1Down:Connect(function(face)
local part = handles.Adornee
if not part then return end
cframeAtMouseDown = part.CFrame
lastStep = 0
local map = faceToAxis[face]
if map then
dragAxis = map.axis
dragSign = map.sign
end
end)
handles.MouseDrag:Connect(function(_, distance)
local part = handles.Adornee
if not part or not dragAxis then return end
local step = math.floor(distance * dragSign * 2)
if step == lastStep then return end
lastStep = step
local rotationAmount = step * math.rad(15)
local worldAxis = cframeAtMouseDown:VectorToWorldSpace(dragAxis)
local rotationCFrame = CFrame.fromAxisAngle(worldAxis, rotationAmount)
local newCFrame = cframeAtMouseDown * rotationCFrame
game.ReplicatedStorage.ChangeCFrame:FireServer(part, newCFrame)
part.CFrame = newCFrame
end)
ye its ai, i dont know how to make rotate but ive made the other 2