How do I tween the Orientation of a Model?
Hello! about your question… if u mean that u want to make a part to rotate infinitely you can’t do that with TweenService. for that, you should use a while loop (i mean, it isn’t the best method because FPS, if u want it to be even more smoothly you can use RunService)
To do that to a model, you need to use WeldConstraints
this is an example:
If you don’t know how to use WeldConstraints
read this: WeldConstraint
After using Welds, you need to change the CFrame.Angles()
of the PrimaryPart of the model in a while loop. (if you don’t know what PrimaryPart is, read this: Model.PrimaryPart)
This would be the code:
while wait() do
game.Workspace.Model.PrimaryPart.CFrame *= CFrame.Angles(0,math.rad(0.5),0)
end
More info about CFrame and CFrame.Angles() here: CFrame.
(if this isn’t what you want, give me more info about what do you want and i will try to help)
Hope it helps!!
If you don’t care about it going infinitely TweenService
would be your friend here.
https://developer.roblox.com/en-us/api-reference/class/TweenService
Btw you would want to change position in the goal table (in the code example section) to orientation
Also, if you want to tween the model to a certain angle, you can use TweenService, like this!
local TweenService = game:GetService("TweenService")
local Model = game.Workspace.Model
local TweenServiceInfo = TweenInfo.new(
2, -- Amount of time that it takes to end the action
Enum.EasingStyle.Quad, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
1, -- Amount of times that it does the action (if u do -1 then it will run infinitely)
false, -- It returns to it's original state?
0 -- a delay
)
local Goal = {Orientation = CFrame.Angles(math.rad(90),0,0)}
local TweenAnimation = TweenService:Create(Model.PrimaryPart,TweenServiceInfo,Goal):Play()
A Tween can only interpolate properties, such as a Part’s CFrame, a Decal’s Transparency etc.
However, a Model does not have any sort of CFrame or Orientation property to tween adn the engine developers didn’t grace us with the ability to make a Tween call a function or method, such as Model:PivotTo()
.
I can suggest some workarounds:
-
Make one part in your model anchored and the rest unanchored. Weld all parts of the model together so it’s rigid. Tween the anchored part’s CFrame.
The rest of the model will move together with the anchored part. -
Tween a part (or possibly even just a
CFrameValue.Value
) and make the model mimic its movement.
local model -- your model
local modelcf = model:GetPivot()
local newcf = modelcf * CFrame.Angles(0, 90, 0) -- let's yaw the model by 90°
local cfv = Instance.new("CFrameValue")
cfv.Value = modelcf -- the proxy CFrame starts at the model's position
local tween = TweenService:Create(
cfv,
TweenInfo.new(5), -- default settings, except it takes 5 sec instead of 1
{Value = newcf} -- CFrameValue.Value is a CFrame. If we were doing this with a part, it would be CFrame = newcf
)
tween:Play()
-- now we make the Model follow the CFrameValue as it changes
local rsconnection = RunService.Stepped:Connect(function()
model:PivotTo(cfv.Value)
end
-- after the tween finishes, break the loop that's moving the model
tween.Completed:Wait()
rsconnection:Disconnect()
model:PivotTo(newcf) -- one last time, just to be sure
- Re-implement TweenService.
TweenService:GetValue() does a lot of the hard work for you.
It becomes easier to make a spinning model, but everything will be more difficult anyway.
Note that you should completely forget about the Orientation property on Parts. It’s a sham and nearly any code that sets or reads Orientation is doomed. It’s meant for rough adjustments to rotation from the Properties window, nothing more. Work with CFrames instead.
By the way, if you want to do something else while you are rotating the model, you can do that in the same script if you just put a coroutine.resume(coroutine.create(function() end))
around it
A better way of achieving the same effect is to use task.spawn
.
Example:
task.spawn(function()
-- code here will run right away
end)
-- code here will also run right away, at the same time.