Help with part rotating WITHOUT PRIMARY PARTS!

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)

2 Likes

Up thread please, i need help!!!

try this if that’s what you’re after

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
1 Like

it doesnt do anything, i linked the model so you can test it out by yourself, thanks for trying!

What exactly do you want to achieve

1 Like


how it looks in studio


image
how it looks in game


it rotates the degrees it not needs to be

Explain step by step what you want to achieve because I don’t quite understand your idea of what it is supposed to do

1 Like

now try to rotate it in studio, and you’ll see the problem


rotate by y

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

1 Like

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)

image

bruh i’m sorry wrong model

I think that’s what you mean


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

1 Like

Yes, it is exactly that i want!!! But are where any ways to don’t change between:

local rotationCFrame = CFrame.Angles(0, 0, angle)
and
local rotationCFrame = CFrame.Angles(angle, 0, 0)

thank you for helping me, i appreciate it sooo much!!!

This means in which direction it will move

1 Like

well, ok, thank you so much for you help, good day or night! thankssss!!!

1 Like

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:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.