How to make a part move a certain distance, but animate it

Hi, the title pretty much says it all. I don’t really know where to start, I have looked at tweens but the only examples I found were ones where it moves it to a set position, not move it along by a certain amount. Thanks for your help in advance!

Can you elaborate on what you are trying to accomplish?

Basically I have a a set of doors and I want them to move outwards and then sideways. However, I don’t know how to make it move from one place to another smoothly or how to animate it.

You mean like some kind of futuristic airlock door? That pops out toward you and shifts to the side? Or are you referring to regular hinged doors.

An airlock door kind of thing, just something that comes out towards you and then goes to the side.

So, you will want to store CFrames in variables for each half of the door. If you are unfamiliar with CFrames, here is a helpful article about them on the devhub: Understanding CFrames

These stored CFrames will be: The closed CFrame, which is also the initial door CFrame, where you placed it. The halfway open CFrame, which is the closed CFrame * a CFrame with however many studs you want it to jut out of the wall. And finally, the full open CFrame, which is the halfway CFrame * a CFrame with however many studs you want it to shift over out of the way.

In case you are wondering why we are using CFrame, its because CFrame positioning is relative to whatever initial CFrame is given. This ensures that the doors move correctly regardless of which way they are facing.

( I say positions here, but they should really be CFrames. )

Once you have these CFrames stored for both halves of the door, you can then tween to them. Follow the instructions on the Tween page of the devhub, and tween the CFrame of the door, not the position.

https://developer.roblox.com/en-us/api-reference/class/Tween

Remember that tweens do not yield for other tweens, so make sure to wait until it is completed by either using a wait() with the same given tween time, or the TweenCompleted event. The former is easier, and is reliable enough.

If your door consists of many parts, then SetPrimaryPartCFrame is how you will move them all in a model together. Of course, if it were me making this door, I would probably just make it a mesh part for convenience so no part shifting occurs with the former.

1 Like

Thank you!! It helped a lot : )