Help with rotating on Pivot

Hello! I’m trying to make a script were it turns a part based on it’s Pivot(Accessed through Edit Pivot). I’m new to this feature, so I wanted to ask how I would get it to work in code. It seems to work fine though when rotating through studio.

4 Likes
local Part = script.Parent
local Pivot = Part.CFrame * CFrame.new(2,.5,1) -- This is the pivot its relative to the world point , here its the top right corner of the part (the default part  of size 4,1,2)
local Offset = Pivot:Inverse() * Part.CFrame  -- Offset between the pivot and the part

while true do
	task.wait()
	Pivot *= CFrame.Angles(0,math.rad(2),0) 
	Part.CFrame = Pivot * Offset
end

You could do something like this , here all you would have to do is change the Pivot and the angle of rotation.

10 Likes

It rotates everything. But here is what I mean. I want it to rotate right here.

What do you mean it rotates everything?

All of the green parts. It rotates those peices. But how do I rotate it on this Pivot Point?

I think you can just use:

Model:PivotTo(CFrame.Angles(x,y,z))

Keeping in mind that the angles are in radians
You can convert degrees to radians using math.rad(degrees)

Yes you would have to find the offset to that pivot point from the part’s CFrame, and it would rotate relative to it.

As an example I tried to use this on a regular part and it worked but it failed on the mesh part…

RotationSpeed = 0.6

while true do
	local pivotCur = script.Parent:GetPivot()
	script.Parent:PivotTo(pivotCur * CFrame.fromEulerAnglesXYZ(0,0,RotationSpeed))
	task.wait(0)
	end

https://gyazo.com/53c16ac22245abfee53ad4f1650238b7 is this what you are trying to achieve?

1 Like

It is, How would I do that with my model?

Yes you would use the script I provided, the part is 18.8 long in the X axis so i divided in by 2 and reduced 2 from it and i got 7.4 and I used that as the point of rotation.

local Part = script.Parent
local Pivot = Part.CFrame * CFrame.new(-7.4,0,0) 
local Offset = Pivot:Inverse() * Part.CFrame

while true do
	task.wait()
	Pivot *= CFrame.Angles(0,math.rad(2),0) 
	Part.CFrame = Pivot * Offset
end
4 Likes

Sorry, just found the issue. the parts had weldconstraints in them so that’s why they all turned at once. Thanks @Razor_IB & @PapaBreadd!