✓ Accepted answer
###Solution
We'll first need to find the offset of the part to the pivot point. Knowing the part's position and the position of the pivot point, we can do this by taking the inverse of the CFrame returned by the toObjectSpace method.
Now that the offset is known, we can calculate the CFrame by multiplying the pivot CFrame by the desired angle and lastly the offset.
Example:
local pivot = CFrame.new()
local part = game.Workspace.Part
local offset = part.CFrame:toObjectSpace(pivot):inverse()
local angle = CFrame.Angles(0, math.rad(30), 0)
part.CFrame = pivot*(part.CFrame - part.CFrame.p)*angle*offset
###Interpolating Rotation
We will need to use some sort of looping structure in order to interpolate the rotation so that it appears as an animation. I will be using a linear interpolation as it is easiest to implement.
I'll show you two of the ways I like to do this, one dependant on duration and one dependant on speed.
Dependant on Duration:
local pivot = CFrame.new()
local part = game.Workspace.Part
local offset = part.CFrame:toObjectSpace(pivot):inverse()
local initialRotation = part.CFrame - part.CFrame.p
local firstTick = tick()
local elapsed = 0
local duration = 1
local desiredAngle = 30
while elapsed <= duration do
local alpha = math.min(1, elapsed/duration)
local angle = desiredAngle*alpha
part.CFrame = pivot*initalRotation*angle*offset
elapsed = tick() - firstTick
end
Dependant on Speed:
local pivot = CFrame.new()
local part = game.Workspace.Part
local offset = part.CFrame:toObjectSpace(pivot):inverse()
local initialRotation = part.CFrame - part.CFrame.p
local firstTick = tick()
local elapsed = 0
local speed = 16
local desiredAngle = 30
local duration = desiredAngle/speed
while elapsed <= duration do
local alpha = math.min(1, elapsed/duration)
local angle = desiredAngle*alpha
part.CFrame = pivot*initalRotation*angle*offset
elapsed = tick() - firstTick
end
3 comments
[THIS MAY NOT HELP SOLVING THE SCRIPT!] Don't discourage yourself, you always have worst people around you of whom you don't even know!
Self-degradation does not make me pity you. It makes me hate you. I hope this pleases you.
^ This pleases me a lot. eLunate, your magic just kills others, but to me, it makes me want to kill you! Wait, ignore that :3