local part1 = script.Parent.Part1
local part2 = script.Parent.Part2
local rotationSpeed = 6
local function calculateCenter()
return (part1.Position + part2.Position) / 2
end
local function rotatePartAroundCenter(part, center, angle)
local offset = part.Position - center
local rotatedOffset = CFrame.Angles(math.rad(angle),0,0) * offset
part.CFrame = CFrame.new(center) * CFrame.new(rotatedOffset)
end
while true do
wait(0.01)
local center = calculateCenter()
rotatePartAroundCenter(part1, center, rotationSpeed)
rotatePartAroundCenter(part2, center, rotationSpeed)
end
I need help with part rotating by itself, Model.rbxm (4.3 KB)
(try to rotate the model by y and it will always place the one way by y)
local part1 = script.Parent.Part1
local part2 = script.Parent.Part2
local rotationSpeed = 6
local function calculateCenter()
return (part1.Position + part2.Position) / 2
end
local function rotatePartAroundCenter(part, center, angle)
local offset = part.Position - center
local rotatedOffset = CFrame.Angles(0, math.rad(angle), 0):VectorToWorldSpace(offset)
part.CFrame = CFrame.new(center) * CFrame.new(rotatedOffset)
end
while true do
wait(0.01)
local center = calculateCenter()
rotatePartAroundCenter(part1, center, rotationSpeed)
rotatePartAroundCenter(part2, center, rotationSpeed)
end
I don’t know if this is what you wanted to achieve try and see, I have created a folder for parts in the model
local partsFolder = script.Parent:WaitForChild("Parts")
local rotationSpeed = 6
local function rotatePartAroundItsCenter(part, angle)
local center = part.Position
local currentOrientation = part.CFrame - part.Position
local rotatedOffset = CFrame.Angles(0, math.rad(angle), 0)
part.CFrame = CFrame.new(center) * rotatedOffset * currentOrientation
end
while true do
wait(0.01)
for _, part in pairs(partsFolder:GetChildren()) do
rotatePartAroundItsCenter(part, rotationSpeed)
end
end
the rotation that i had already done is good, but the only thing is that if you rotate the model in roblox studio BY Y, and that go to play, it will get rotated by script , i’m linking you another model just go to play with it and you will see the problem Model 222.rbxm (4.7 KB)
local part1 = script.Parent.Part1
local part2 = script.Parent.Part2
local rotationSpeed = 0.05
local function calculateCenter()
return (part1.Position + part2.Position) / 2
end
local function rotatePartAroundCenter(part, center, angle)
local originalCFrame = part.CFrame
local offset = originalCFrame.Position - center
local rotationCFrame = CFrame.Angles(0, 0, angle)
local rotatedOffset = rotationCFrame * offset
local newPosition = center + rotatedOffset
part.CFrame = CFrame.new(newPosition) * originalCFrame.Rotation
end
while true do
wait(0.01)
local center = calculateCenter()
rotatePartAroundCenter(part1, center, rotationSpeed)
rotatePartAroundCenter(part2, center, rotationSpeed)
end
local part1 = script.Parent.Part1
local part2 = script.Parent.Part2
local rotationSpeed = 0.1
local model = script.Parent
local function calculateCenter()
return (part1.Position + part2.Position) / 2
end
local function rotatePartAroundCenter(part, center, angle)
local originalCFrame = part.CFrame
local offset = originalCFrame.Position - center
local rotationAxis = model[INSERTYOURPARTHERE].CFrame.UpVector
local rotationCFrame = CFrame.fromAxisAngle(rotationAxis, angle)
local rotatedOffset = rotationCFrame:VectorToWorldSpace(offset)
local newPosition = center + rotatedOffset
part.CFrame = CFrame.new(newPosition) * originalCFrame.Rotation
end
while true do
wait(0.01)
local center = calculateCenter()
rotatePartAroundCenter(part1, center, rotationSpeed)
rotatePartAroundCenter(part2, center, rotationSpeed)
end
btw if someone needs a model that will auto rotate based on another part here’s: