I essentially want to tween a door which has a hidden Hinge part (not related to contraints). I use Model:SetPrimaryPartCFrame() to animate the door. However I’d like to use the TweenStyles from TweenService. Is there a way to apply this?
I recommend instead using a “root” part to your model and welding everything to it.
Then just use TweenService on that root part.
You’ll get much more reliable results.
What Osyris said – or if you don’t like that, make a custom tweening function and make a custom weld system so it positions the parts relative to the root part (why? works when the parts are anchored).
I’m not sure if you’re aware of it but SetPrimaryPartCFrame probably isn’t the best to use when animating. Floating point inaccuracies add up over consecutive calls and eventually you get parts that start to be offset the root part differently than they were before.
If you call it enough times its possible parts of the door will be studs apart from each other.
Make a function that creates a CFrameValue and tween that value with TweenService. Listen for CFrameValue.Changed and :SetPrimaryPartCFrame to that value.
To illustrate what other people above have already warned about;
Using SetPrimaryPartCFrame for animations will cause your model’s parts to get disjointed, like in the above gif.
What Osyris posted is your best answer. If you don’t want to do that, use constraints.
How to do perform:
- Pick a root. Preferably an invisible part without collisions enabled and it encompasses your model.
- Weld all parts in your model to this root part with Motor6D and Motor6D only. Unanchor welded parts but keep your root welded.
- Do your tween stuff on the root part.
Things to be wary of:
- Explosions will tear your model apart because they hang on via motors; they aren’t anchored
- Scarcely use SetPrimaryPartCFrame, it will offset your parts from your root and it’ll become noticable after enough uses
Like I saw someone say; It is best to make a function that constantly positions all parts relatively to the root part, because my doors and gates are anchored. Should I use a table to store all the relative offsets? Or are there better ways to go about it?