Rotate model with tween, how?

So i have this model that i created, i just want to rotate it to the transparent part with a tween, how would i do that?

here is my tweening code:

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!

You could use AssemblyAngularVelocity or a related function to simulate a tween, if your model is an assembly (connected).

you could make a loop that rotates the model each time

like this (just change which value rotates)

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)

Sure, but that will not look smooth because with each physics simulation step you will have the same orientation.

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)

The signal that GetPropertyChangedSignal returns only fires each frame.
It would be good that Roblox give us a way to directly tween models.

1 Like

You’re right, but I suppose that’s the only option for now

2 Likes

thx, u mean like a primary part within the model and just tween the primary part with everything else welded together?

If so, then ik what ure talking about!

We should contact them about that

That will not work. Tweens do not take into account any physics constraints while tweening.

hm weird, ive seen multiple other forums suggest something like that

This is what i was thinking:

  • Have a primary Part
  • Weld all parts together then model them
  • Tween just the primary part to a certain angle degrees rotation

Then the entire model would have rotate it slightly then back with a simple tween

I’ve just tested it and it doesn’t work. It just moves the primary part but the welded part does not follow it.

hmm weird, maybe if you PivotTo(–CFRAME–) with a lerp ?

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)

ill see what i can do with MY knowledge, thakns for the tips tho

local TweenService = game:GetService("TweenService")
local movingModel = script.Parent
local goalPart = script.Parent.Parent.Point1

do
	local cfv = Instance.new("CFrameValue")
	cfv.Value = movingModel:GetPivot()
	cfv.Changed:Connect(function(new_cf)
		movingModel:PivotTo(new_cf)
	end)
	local tween = TweenService:Create(
		cfv,
		TweenInfo.new(
			4, -- time
			Enum.EasingStyle.Cubic,
			Enum.EasingDirection.InOut,
			-1, -- repeat (-1 = inf)
			true, -- reverse?
			0 -- delay
		),
		{
			Value = goalPart.CFrame
		}
	)
	tween.Completed:Once(function()
		cfv:Destroy()
	end)
	tween:Play()
end

ill try it out, ill let u know if it works and mark it as a the solution! :slight_smile:

got an error, the same one from always