Smoother Animation for Models?

Currently, my trains move by changing the PrimaryPartCFrames’ Positions in a loop. It seems to workout out so far. However, I have a couple of issues with it.

  1. I feel that since each train has a loop for movement, it might cause some lag for either the Client and/or the Server.
  2. Sometimes, some of the parts of the train glitch and look like they are not moving every second or two.

https://gyazo.com/7a25ec973f4f807c66eefd6d46250779

I was wondering, is there a more efficient way of having the trains move besides my method?
Thank you.

1 Like

If you have the movement done in a client-side script it should be smoother.
I’d also recommend that you use the TweenService rather than CFrame.

1 Like

I would recommend you check out this post on using TweenService for models:

Model Tweening

Quick synopsis:

What can we do to change our approach?

The new approach I applied was actually quite neat. It gets the job done, produces no errors if done >right and I can litter the code anywhere I wish, the way I like to script. So, here are the steps.

  1. Create your model however you want. Use your existing model if you have one.
  2. Create an invisible part. This will act as your root.
    • If you intend on tweening the entire model, have the invisible part cover the model in its exact dimensions.
    • If you intend on making a pivot of sorts, make it scale up one way. Image example will be Figure >1 at the bottom of these steps.
  3. Weld all parts to the invisible part. Unanchor every part and set up collisions however you wish. >Leave the invisible brick with anchor on and CanCollide off. You must use Motor6D.
    • I use a personal mod of Ozzypig’s Weld Plugin to quickly accomplish my weld work. Instead of using ManualWelds, it’s changed to use Motor6D.
  4. Do your tween work on this invisible part. You’re done!
2 Likes

I mean, I don’t really know if this is a more efficent way but it will take care of the problem with PrimaryPartCFrame, don’t know the problem?

When repetdley using SetPrimaryPartCFrame for too much, it can cause parts to offset slowly overtime, making it more and more noticeable. What you could do is have a part that will be moved thats anchored, and the decorational pieces like the train be unanchored and welded to the anchored brick. Tween that brick forward towards its path and it should behave like normal.

^^^ Model tweening thing explained better

2 Likes

My tutorial on tweening models isn’t a catch-all case. You can still have unsmooth animations after following that tutorial. At the very least however, the smoothest animations will come from the client, rather than the server. Therefore, aesthetic effects should be left in the hands of the client.

3 Likes

This has been pretty much answered by having the animations done on the client. I remember seeing a module somewhere that would tween something for all the clients, but the server does nothing. Once the tween is done, the sever updates the CFrame of the tweened object. If I manage to find this again, I’ll get back to you :smiley:

Edit: here it is. TweenService V2

1 Like