Tweening Models

I been working with the Tween Service for awhile and it’s been doing me absolute wonders on my productivity, however it has a drawback. I can’t seem to use it on models.

Anyone know a good method that’s cheap on performance such as the server to perform tweens on models? I know there is lerp but is there another option?

22 Likes

EDIT 09.06.2020: Hi there, 3 years later. Developers are still finding and/or linking this post. I do not recommend using this method as it possesses a few problems; please instead see my tutorial on how to tween models for a more updated method. There’s a note on the thread I linked as well about this. For an immediate answer as to why this is bad, see As8D’s reply.


Given you’re a member, I can link you to a post I made on the same topic since I too was struggling on how to tween models. You can check there for any replies that are adequate for answering your inquiry:

I like this solution best (haven’t experimented but I’m sure it’ll work):

For basic users who can’t see the post, I’ll put a quote of the code that I’m speaking of:

local tweenService = game:GetService("TweenService")
local info = TweenInfo.new()

local function tweenModel(model, CF)
	local CFrameValue = Instance.new("CFrameValue")
	CFrameValue.Value = model:GetPrimaryPartCFrame()

	CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
		model:SetPrimaryPartCFrame(CFrameValue.Value)
	end)
	
	local tween = tweenService:Create(CFrameValue, info, {Value = CF})
	tween:Play()
	
	tween.Completed:Connect(function()
		CFrameValue:Destroy()
	end)
end

(posted by @Tunicus)

74 Likes

:warning: Beware of using SetPrimaryPartCFrame for repeated use, though!

http://i.imgur.com/A1MdqND.gif
^ Notice the visible gap in the model due to floating point errors

If you want to tween your model without possibly distorting it, you can weld up all parts to a root part, and simply tween that part as the anchor - if your goal is to tween its CFrame property. Stuff like tweening the scale/size or transparency of a model will need you to go through something like model:GetDescendants(), find the BaseParts (or other applicable classes) and tween those.

22 Likes

I know that this response is late, but you could always just put the model in a folder, ungroup the model, then tween each part. Just a thought that occured. :man_shrugging:

Super inefficient and not a good method. Right now, I weld all my parts to an invisible part (root) with Motor6D, then unanchor everything except that root, then tween the root.

3 Likes

Yea that is much more efficient. :joy:
I tried doing welds but I failed, so i was like Imma just do it another way.
The welding way is definitely more efficient.

1 Like

Do you know for a fact that unanchored parts don’t have physics run on them if they’re welded to an anchored part?

1 Like

I don’t know that for a fact. I just pray that none of my scripts break the welds from the door or that I don’t use explosion objects. As far as I’ve gone (which is only welding unanchored parts to an anchored part), I’ve seen absolutely no issues or physics-related problems.

2 Likes

If you want to use something like ‘SetPrimaryPart’, but avoid the brick shift then I’d recommend checking out this article:

It will allow you to keep parts anchored and not use welds if you wish to avoid that.

7 Likes

I apologize for bumping this topic, but since my question is about this reply, I didn’t see the need to make another repetitive post on this topic.

I tried testing out this code, and it worked, however, I am running into an issue I can’t figure out. If I try to manually set the CFrame of the primary part just like:
workspace.ReturnCorridor01:SetPrimaryPartCFrame(CFrameHere)
and then tween that same model using that tween code, everything works fine.

But if I reverse this, and I try to tween the model and then set its primary part CFrame, the tween works fine, but I can’t change the primary part CFrame after. Any idea why this is happening?

I have ditched the method of using SetPrimaryPartCFrame since posting that and now opt to weld parts to a root, much like what As8D posted. I only now use SetPrimaryPartCFrame in the off chance that I need it, if I’m too lazy or if a custom implementation won’t cut it.

As for the issue you’re experiencing, I don’t fully know exactly what you’re saying or how this is being set up in practice, so I don’t really know how to explain to you the problem. I wasn’t the one who wrote the code either. The only thing I can really tell you here, which may not even be what you were asking, is that you can’t modify properties mid-tween as they’ll be overwritten by other intermediate frames of it.

2 Likes

Well from what it seems like, the tween doesn’t seem to be stopping its influence after it has completed.

Anyway, I have welded everything to the primary part. Should I just change the CFrame of the primary part normally?

If you are taking up the above advice, yes, just modify the PrimaryPart normally and all other parts will follow along. For the sake of movement accuracy, it’s recommended your PrimaryPart be a bounding box as opposed to a part of the model itself, but anything works.

3 Likes

Hello! I know a ton of time has passed since this post was uploaded! Although, i don’t feel good not sharing what i’ve found! So there is actually a way to tween models A LOT easier! The only thing you have to do is unanchor the model, set a primary part, add weld constraints from the primary part to every other part, and use the tween service normally! Now where the primary part goes, the other parts will follow! A weld constraint plugin helps too!

3 Likes

That’s fairly similar to what @colbert2677 posted above, but I prefer to use the method he specifically stated: using a bounding box. This is especially helpful/useful if/when you are trying to tween a model that contains custom meshes.

4 Likes