I’m Awesome_0A and I’ve been scripting for a long time now. I mostly specialise in general scripting so you’d think I’d be good at this but my brain is just not ready to script today so I made this post to ask for assistance from the community.
My issue is that I am unsure of what method to use to make a train (model) follow a specific pre-set track. The track will have turns and straights so the train has to be able to adapt to that and stay on the track. I was thinking about using Vector3 and checking if the trains wheels are colliding with a track and if so move forward 1 stud in the direction of the track and repeat but I can think of a million issues using this method.
How would you do this?
I was actually wondering the same thing, since I will need to make a pushable cart in my game follow a certain path. Tween Service is definitely not an option, because for a path with lots of turns you would have to create tons of tweens and unnecessary path nodes. I havent come up with a solution yet. If someone offers a good solution, tag me
Please try that Search tool up top. There have been a lot of posts about trains, some using physics Constraints, and others using CFraming.
I’ve used a simple setup that allows the train wheels to ride on the tracks with HingeConstraints. I made it as a training aid for another person in this post: How to make a basic train - #12 by Scottifly
If you need the bogeys to pivot then you can put 2 axles on the bogey, hinge it at the center, and put 2 of the red inner alignment wheels at either end of the bogey.
Maybe this video could be of help to you.
Yeah I was going to search it but I wasn’t sure what the search terms would be since I assumed this wouldn’t be a ‘hot topic’
The tutorial is great and all but I would need to weld everything together and this train model easily has over 5000 parts. What would you recommend doing to counter this problem? I don’t really look forward to spending 12 hours making welds.
Go into blender and create a train. You should not move models with such amount of parts.
I’m a programmer and this train was given to me to script. I can’t turn around and say “remake it”
It can for sure give you a lot of trouble performance wise, moving 5000 parts around all the time.
Imagine the parts being LEGO bricks. It will for sure cause more lag having a train made out of individual LEGO bricks, than having it molded into one.
try my plugin it should help:
I think scripting this takes too long, I would just suggest rig the train and animate it, then put a script playing the train moving along the tracks.
As stated by others, you can build the train with Anchored Parts and a simple weld script that welds the parts and unanchors the parts. The only issue is the time it takes can lag a place loading if you have a lot of Parts and it has to weld every time it’s made.
If the train was given to you to script you can tell the builder that it needs to be cleaned up to reduce Parts, or that they need to weld it together. If they gave you an incomplete model that is their issue, not yours. @TortenSkjold it already looks like it’s made of Meshparts.
You said the entire model is 5000+ Parts, but is that the entire train, or just the engine? If the builder made the complete train with an engine and 10 identical cars they only need to weld the engine and 1 car and then copy/paste that in place of the other cars. As TortenSkjold said, moving that many Parts is going to cause problems.
I wasn’t referring to that he didn’t already use MeshParts, I suggested that he went into Blender. Because the train is surely made out of too many parts.
I have found that if you select a bunch of parts in explorer and then weld, they will all weld together in one shot. 5k parts is a lot, and that’s not going to help with performance, especially when there’s scenery stuff to consider. You could try reducing the parts count by making unions.
I haven’t watched the tutorial, but from what I have seen of those cart riding games, there’s two parts that stick down from the cart that sits between the tracks on the inside. Then I believe you can use a constant force to move it.
I’ve got an idea following on from the weld idea.
I could turn each carriage into a giant union and then weld them all together from there. What issues would this cause if I were to do it this way?
Just realised most of the parts are mesh parts whilst the actual train itself is not a mesh so making a giant union will not work.
I was considering this although I would prefer the train support track changes meaning it will still work despite the track conditions.
The easiest way to weld multiple parts together without any plugins is the following:
Select all parts within the model. If you want to multi-select, click the part closest to the top of the model, hold shift, then click the part at the bottom of the model. Or, right click the model, and click “Select Children”
From here, you can simply click the arrow underneath the “Create” button (found in the model tab) and click on “Weld”
Not the whole fix to your issue, but at least it will help with welding parts
TLDR: select all parts and click “Weld” in model tab > create > weld button