Rotating a part using pivot points

Roblox recently added the new Pivot Offset Position and Pivot Offset Orientation property.

I have modified the offset position so it is at the end of a part like so:
image

And when I manually rotate it, it rotates just like I want it to. Not around it’s own axis, but around the pivot point (as if it was stuck on the end).

However, I have come across hardships when doing this with scripts. I change the pivot point, that is no issue. But when I rotate it (with a for loop) it acts as if it has the “standard”/default pivot point.

My script:

for i = 0,100,1 do
	print(i)
	script.Parent.Orientation = Vector3.new(0,i,0)
	wait()
end

And I change the pivot point by just typing:
part.PivotOffset = CFrame.new(0,100,0)

Any help is appreciated, thank you! :slight_smile:

2 Likes

Subtract the position of where you want to rotate about from the position of the part, then apply the rotation, then offset the part by the position you subtracted originally.

What this does is basically center the position you are rotating about the origin, then rotates it about the origin, then positions it back relative to the position rotated about.

Pivot points are in beta at this moment, if I am correct you are unable to use them for anything like this.
If you do want to rotate a part around a certain point use the following:

local PivotCFrame = CFrame.new(PivotOffset) 
Part.CFrame = Part.CFrame * CFrame.new(PivotOffset) * CFrame.Angle(0, math.rad(i), 0) / CFrame.new(PivotOffset)
1 Like