How would I tween the orientation of a model?

So I have a crate, which I need to spin. I want change the orientation of the model to spin it, with tween service. The problem is that you can’t do this with a model without welding it. Is there any way I can do this without welding my model together. If there is none, how would I weld my model together?

2 Likes

Welding is best, but also possible, but quite laggy is to tween cframevalue, and every frame, set it to model by :SetPrimaryPartCFrame
And for welding, there are many plugins

I made a tutorial on tweening models. One of the code samples is on model rotation.

There are definitely other solutions you can use and you don’t have to weld a model together in order to tween it, though it’d be preferable especially for a moving assembly. I’d recommend welding your model together or sharing why you don’t want to use welding if you’re opposed to it.

@mistr88 This is a bad method. I encourage you to read my above linked thread as it talks about the method you listed specifically, which is to tween a CFrameValue and use SetPrimaryPartCFrame. Scroll near the bottom to find it. To be short and sweet about it: it’s unnecessary work for your code and it tears apart models.

3 Likes

i saied, that welding is best, but he wants this:

I addressed this in my reply but very vaguely. I suppose I owe that an explanation. Regardless of this, I still stand by what I said and I encourage you to read the thread where I talk about your proposed method [2], where I go into depth about how it’s bad and that you should avoid using it.

You are able to accomplish model tweening in several different fashions. The main thing to understand about tweening a model is that model tweening doesn’t exist, what you’re doing is tweening a part and moving the rest of the assembly relative to it. You can, therefore, take this concept and apply it to a solution you feel best fits your case.

You can very easily set up a tweening helper module or something similar that moves the PrimaryPart of a model passed as an argument and then offset all other parts to this tweened part. If you have nested models, you can write a recursive function that treats the PrimaryPart of those models as a child part of the aforementioned passed model, then move the other parts relative to that PrimaryPart.

ik, that this is offtopic
i readed it 2 months earlier

that i understood before i readed your post, because tween is editing parametrs, and i cant move whole model (without welds) using parametrs

Do you just want to spin it continuously? You can just do this every frame:

[cratemodel]:SetPrimaryPartCFrame([cratemodel].PrimaryPart.CFrame * CFrame.Angles(0,math.rad(2),0))

The number 2 in math.rad(2) is the speed. Make sure you have a PrimaryPart set up

You need to weld the parts for that right?

No you don’t have to, all parts in a model will be rotated relatively to the primary part.

How would I do this using tween?

I’m a little distraught that my feedback was skipped over. You should never use raw SetPrimaryPartCFrame. I’ve outlined the problems with it in the thread I linked earlier. Use a custom implementation that involves you offsetting it manually or just use welds. Not sure what the aversion to using welds is here.

Earlier response I made:

Hello, there is something called the Roblox Tween Service which allows for transitioning from one state to another it can be used like so: `local TweenService = game:GetService(“TweenService”)

local part = game.Workspace.MyPart -- The part you want to transition eg "The Crate"

local goal = {orientation = Vector3.new(0,360,0)} -- The goal you want to reach with your part eg "Orientation" Property


local tweenInfo = TweenInfo.new(
	2, -- Time for the spin of the crate
	Enum.EasingStyle.Linear, -- EasingStyle this does not need to be changed but for a diffrent animation look change this
	Enum.EasingDirection.In, -- EasingDirection
	2, -- The amount of spins the crate does
	false, -- Reverses (tween will reverse once reaching it's goal) do you want your crate to go back and fourth
	0 -- the time between the tween:Play() function and the tween platying
)

local tween = TweenService:Create(part, tweenInfo, goal) -- your tween
tween:Play() -- play your animation`
2 Likes

That doesn’t explain how can I use that with a model.

2 Likes

Are you using a viewport frame in a gui

Yes but it is a model, so I can’t tween the model’s position because it doesn’t have one.

Do you have a primary part in your model?

You could do something like this:
local model = game.Workspace.MyModel

local cframe = model.PrimaryPart.CFrame -- Current CFrame

for i =1,360 do

model:SetPrimaryPartCFrame(cframe * CFrame.Angles(0, math.rad(i), 0))

wait()

end

Also no welding is needed!

As @colbert2677 has mentioned several times, this is not a optimal method. Floating point errors will cause the model to shift apart over time, and overall there are better ways to do this.

If you want to avoid welding, their are also solutions to this. Picking a quick and easy method does not make it reliable.

Please read the past replies before posting your own.

1 Like