local TweenService = game:GetService("TweenService")
local movingPart = script.Parent
local point1 = script.Parent.Parent.Point1
local tweenInfo = TweenInfo.new(
4, -- number of seconds to complete
Enum.EasingStyle.Cubic, -- how it moves
Enum.EasingDirection.InOut, -- how it moves too
-1, -- how may times it repeats
true, -- reverse too aka go back to start
0 -- seconds before starting
)
local properties = {
["CFrame"] = point1.CFrame
--["Position"] = point1.Position + Vector3.new(point1.Position),
}
local tween = TweenService:Create(movingPart, tweenInfo, properties)
tween:Play()
This is an interesting issue.
Now for movig models there exists the function PiviotTo(), but obviously this isn’t tweening.
An idea I have in mind would be for you to create an invisible and anchored part outside of the model place it exactly where the model’s position is. Then use a Weld constraint to connect the model with the part. Use the tween on the part and it should work, I believe.
P…S. I can’t test this myself right now, but I hope it will work. Good luck!
local RunService = game:GetService("RunService")
local model = script.Parent
local speed = 360 -- degrees per second
RunService.Heartbeat:Connect(function(deltaTime)
model:PivotTo(model:GetPivot() * CFrame.Angles(math.rad(speed * deltaTime), 0, 0))
end)
I’m not sure if this is the best approach, but here’s a piece of code I wrote. I got the idea from a post on the DevForum, though I don’t remember the exact source
local function TweenModel(Model, Tween_Info, Result)
local CFrameValue = Instance.new("CFrameValue") do
CFrameValue.Value = Model:GetPivot()
end
CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
Model:PivotTo(CFrameValue.Value)
end)
local Tween = TS:Create(CFrameValue, Tween_Info, {Value = Result})
Tween:Play()
Tween.Completed:Connect(function()
CFrameValue:Destroy()
end)
end
-- Example Usage:
local Model = workspace.Model -- Replace with your model reference
local GoalCF = CFrame.new(0, 0, 0) -- Target position
local Tween_Info = TweenInfo.new(5, Enum.EasingStyle.Linear) -- Duration and easing style etc
TweenModel(Model, Tween_Info, GoalCF)
I’ve made a simple example following that approach:
local asmRoot = workspace.Model:FindFirstChildWhichIsA("BasePart").AssemblyRootPart
local start = asmRoot.CFrame
local init = os.clock()
local time = 5
local endTime = init + time
local goal = CFrame.new(5, 5, 5) * CFrame.Angles(math.deg(- 90), 0, 0)
local conn
conn = game:GetService("RunService").Heartbeat:Connect(function()
if os.clock() > endTime then
asmRoot:PivotTo(goal)
conn:Disconnect()
else
asmRoot:PivotTo(start:Lerp(goal, (os.clock() - init) / time))
end
end)