Changing the CFrame of a model smoothly

I have a door that consists of two parts which reside in a model. I am currently using SetPrimaryPartCFrame() but it is noticeable that the parts of the model don’t move together as a whole (creating a jittery effect).

What other method would I go about using to fix this issue?

1 Like

You can use welds+constraints to keep the door together and move it as a whole using physics. That way Roblox takes care of properly interpolating the door for you.

The category #development-support:scripting-support is a better place for this FYI

2 Likes

I will investigate that, although I was hoping for some CFrame related method.

Thanks for the reply.

I had the same problem recently. I was trying to use TweenService with a model but there is no possible way to do so. You have to settle with CFrame:lerp() or try what @buildthomas said.

You can create a table of all relative cframes of the door parts to a main part

In some sort of renderstepped loop, update the cframe of the main part. Then in the same frame, loop through the rest of the door parts and reference the table of relative cframes and set those cframes accordingly for each part.

I can probably come up with a code example if you have trouble seeing how this would work.

Cool idea, I will be sure to try this out.

I’d use physics and body movers or animation for things that depend on smooth consistent movement

I asked a question similar to this much time ago. I like this solution best.

For basic users unable to view the post, I’ll post the code:

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

(code belongs to @Tunicus)

Unfortunately, at the moment, SetPrimaryPartCFrame will start to tear your model apart after repeated usage.

5 Likes

This is unnecessary if you just use PrimaryPart and Model:SetPrimaryPartCFrame. It does this for you except in C++ so it’s faster than Lua.

This would help, only if OP didn’t state that he is already using SetPrimaryPartCFrame and is looking for other methods. :stuck_out_tongue:

My point was that it’s the same as SetPrimaryPartCFrame except slower :wink:

I’m going to point out that if you are moving the model every frame, at some point SetPrimaryPartCFrame will run into floating point issues and parts will start offsetting into weird places.

This is why the table method is still necessary for certain cases until those issues can somehow be fixed, which I doubt it can be if a model is being rotated around and moved into all sorts of cframe orientations.

2 Likes

Weld the parts of the door to the primary part. Use SetPrimaryPartCFrame. Solved.