I want to make an on-rails system like the trains of The Wild West and Jailbreak. For my use case, CFraming the vehicles is mandatory. These games’ train cars have multiple parts, and they have to be moved together otherwise the parts will separate and the model will look ruined.
There’s a few ways this can be done:
Unanchored parts with welds connecting to an anchored base brick that is CFramed
Setting the CFrame of all parts individually
Calling ::SetPrimaryPartCFrame
For one of my use cases, the first one is probably not feasible since it will be occurring in a ViewportFrame which has no physics.
SetPrimaryPartCFrame has the downside of compounding floating point errors but this can be alleviated by setting the CFrame of all the parts individually.
For my use case, fast updates are the most important part. The trains of these games are very smooth moving, so I am curious what the most performant method is. I hope to have over 20 train cars moving at once, and each train car can have anywhere between 20 and 150 parts.
There have been many instances in my games where I’ve smoothly moved models of parts from point A to point B with little to no lag or performance issues. To me, the methods you have listed are all feasible, though the first option, “Unanchored parts with welds connecting to an anchored base brick that is CFramed” seems most reasonable to me.
In most scenarios, I have welded the model’s parts to its PrimaryPart and performed the necessary operations to move the model by CFraming the PrimaryPart, tweening it, attaching a prismatic constraint to it, etc. As you have mentioned, repeatedly calling SetPrimaryPartCFrame is inefficient and will lead to spacing offsets of parts (if not welded).
This would definitely seem to be a problem if a train were to run in a viewport frame. There are two methods to counter that, though I am unsure of whether or not they may contextually fit for your game.
Rather than moving the model in the viewport frame (because you can’t, since physics isn’t simulated in the frame), you can move the camera to give the visual effect that the train is moving.
You can update each individual part’s CFrame in the train model that’s in the Viewport.
As for performance, you mention how you would want this to be smooth moving. Unfortunately I do not have much insight to give on that. Jailbreak has smooth moving trains. The only solutions I can think of are:
The physics and movement is being replicated to the client
SetNetworkOwnership is being used somehow somewhere
I hope this was somewhat helpful. If you’d like me to elaborate on any ideas, please shoot a comment down