Tweening using PiviotTo

Right now I am trying to create a object that will spin around in circle’s. So I moved the PiviotPoint to where if it is rotated it will appear to be rotating in a circle. However PiviotTo is not working how I want it to work, and it’s just teleporting the part instead of tweening it.

Is there anyway to make a smooth tween using PiviotTo, while also delivering the appearance of a part rotating in a circle?

Here is my test code:

part = script.Parent
tweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(
	5,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out, 
	-1, 
	true,
	0
)

wait(10)
tweenService:Create(part,tweenInfo,{CFrame = part:PivotTo(part:GetPivot()*CFrame.Angles(0,math.rad(90),0))}):Play()

Here is a video on how its preforming:

Here you are Applying a New CFrame, and not Adding on a CFrame

I believe this is what you are looking for:

tweenService:Create(part,tweenInfo,{CFrame = part.CFrame * CFrame.Angles(0,math.rad(90),0))}):Play()

1 Like

This does tween the part, but it doesnt tween it around the piviot point I have created.
Do you have any other ideas or answers?

I understand the most of the documentation I just don’t know how to make it tweenable.

You could create a CFrameValue, set its value to the current CFrame, then tween it to the end CFrame, and then detect the changes of the CFrame value and apply it to the pivot:

local part = script.Parent
local tweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(
	5,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out, 
	-1, 
	true,
	0
)

wait(10)
local cframeValue = Instance.new("CFrameValue")
cframeValue.Value = part.CFrame
-- detect value changes
cframeValue:GetPropertyChangedSignal("Value"):Connect(function()
    part:PivotTo(cframeValue.Value)
end

-- tween it
tweenService:Create(cframeValue,tweenInfo,{Value = cframeValue.Value * CFrame.Angles(0,math.rad(90),0))}):Play()

For garbage collection i recommend you to delete the CframeValue after the tween ends, also use local scoped variables, because lua reads them faster than global ones, plus you dont need it to be global anyways

Thank you so much!
Although you did forget to change the last line from CFrame = to Value =
Thank you for the explanation though

I see, i was in a hurry so didnt notice lol

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