Tweening Models?

How would I make a model where, once clicked on, it is tweened to a new position? I am new to tweening, and I can’t figure this out. Thanks!

Tween the PrimaryPart of a model to tween the entire model. If a model doesn’t have a PrimaryPart, give it one.

Example:

local tws = game:GetService('TweenService')
local pos = CFrame.new(0, 100, 0)
local car = workspace.Car
local twinfo = TweenInfo.new(1)

tws:Create(car.PrimaryPart, twinfo, {CFrame = pos}):Play()
3 Likes

So there are two ways to approach this: the old way and the new way.

The old way would be to create a WeldConstraint between each part and then tween the CFrame of a single part and it should maintain the position.

The new way would be to tween a CFrameValue and then when the CFrameValue’s value changes, you can use the new model:PivotTo method to move your model.

4 Likes

Which way is more effective? Or do the methods get the same results?

I’m not sure what one’s more performant but they should both get you the same results visually.

2 Likes

cc @7z99

I would say PivotTo. I don’t have the exact technical details here but welds are managed by physics simulation. Parts welded to another are treated as anchored and are updated in relative positions although they do rely on the root. Not a good plan if your experience relies on joint-breaking instances like explosions and you want to retain the joint breaking behaviour.

PivotTo moves all CFrames in a similar fashion to or directly implementing BulkMoveTo.

Visually they are the same, but CFrame is the least expensive property to update in the engine so in theory PivotTo is going to be better than welds, albeit negligibly. You also don’t have to rely on unanchored parts and physics simulation and can keep your models anchored.

5 Likes

It took a while, but now I have the model set up using welds, and I understand a little bit about tweens. How would I tween the primary part in the model when the player clicks it?

1 Like