Hi, I’ve created a chassis for a train thats based on physics and it works great, however when there starts to get a few carriages it will start to go bad and not look great so I’m looking at converting it into a CFrame based train instead of a physical train.
It should have exactly the same behavior but much smoother, and shouldn’t be shaky, and if I’m right you can make CFrame train go faster than an areoplane or rocket ship without derailing?
I don’t want to use loops or nodes and it should be able to be player driven.
Heres a placefile of the chassis and how it looks (Uses LinearVelocity.Line to move), how can I get the same result but as CFrame train?
I also have the same Issue, I have wanted to make a train game for a while, and this exact problem of getting when a train should turn is complicated. I am not currently working on a train game rn as my attention is on other projects, but I did message a developer of the game FACTORIO, which does have a train system, who had this to say:
Email
“I am not sure what exactly would you like to know, when a rail is placed it has to perform some amount of entity searches around its conneciton points to find nearby rails and to connect with them. I am not going to describe how it was implemented in 1.1.x as it was a nightmare to work with. In general (as it will be in 2.0 when it goes out) given rail piece knows where it has connection points (where a connection point is described by a map position and direction) and for given connection point there is a specific point certain distance out of the rail (connection point’s center shifted by 0.7 tile along the connection direction) where an entity search is performed. Rails that are found are checked if they have a connection point at the exact same position but opposite direction and in such case the rail is considered a neighbour and they are connected (meaning some pointers are set to point at the other rails). Rails draw their endings when they see all 3 connections on given end are not connected (we keep separate pointers for left/straight/right connected neighbour for each end).”
He linked to a discord post saying:
Discord Post
“without looking into the old rails code its hard to appreciate how huge a technical debt was hiding behind a “hard-coded connectivity rules”, there was basically a spaghetti connect/disconnect code where literally every single case of a rail was implemented independently, like: “if this rail is curved-rail with direction East and the connection to setup is back, for the straight connected rail search for straight-rail at this.position - {5,1} with direction East, for left connected rail search for curved-rail at this.position-{8,3} with direction SouthWest and for right connected rail search for curved-rail at this.position-{8,-5} with direction West” or something like that”
…
“it was just too much, having like 400 lines of code just of all the cases a straight and curved rails could connect to each other was clearly an obstacle that was not allowing for anything more complex than the 2 shapes. So i had to basically reimplement that entire logic to get rid of that spaghetti connect/disconnect code and instead all rails say “my front connection is at {-1,0} with direction West and is turning straight, my back connection is at {1,0} with direction East and is turning straight”, so when a rail wants to connect it just performs entity search nearby the connection point and knows if it can bind to given rail by means of those connection point definitions”
From all he says it seems like the train is just a point moving from rail piece to rail piece. And each rail piece links to the one before or after. This will take some ingenuity on our part. As I have interest in this area I would love to help you and maybe we can learn from each other.
I hope all this information wasn’t too much and I’m sorry I cant help any more than this, I got all excited as this is also on my ideas list of things to make.
Take Care!
I’m just going to drop this here Train Test.rbxl (72.8 KB)
This was a project I started from a couple years ago, and it’s a CFramed train. I never got to the logic of switching tracks but I hope this can be useful
If you have any questions, send me a reply or a private message, I’m going to bed now
Edit: Unfortunately, I believe that this is a node based or similar system which isn’t quite what I’m looking for, sorry.
Does this use nodes or how does it work? I can’t see the code right now because I’m on my iPad but I’ll take a look soon.
I also should be going to bed too for my health (Or better sleep or something I don’t know), but… I’m not lol its only 11:00pm from when I replied with this
If you’d like we can work on a train system together! Were you thinking about an entire system or just a chassis if you were wanting to work together?
I’m thinking a chassis because the signalling system I’m using is based off of the signalling system my country uses and the train system is also based off my country and you might not like a lot of the things from it.
I don’t get what you mean by the difference between a whole system and a chassis, but I will definitely be willing to work together on this.
I’m sure the train system based of of your country will be fine, but in your previous post you mention that you don’t want a node system, If not how would you want to do this?
Train system: Doors, signals, switch tracks, basically an entire train with features and things. I’ve already put 1 years work into this though.
Train chassis: Basically the “engine” that moves
I was thinking more of a wheel sensor thing that knows if its at a curve. Maybe raycasts (not very performant and i’d have to do one around where every bogie is so thats about 4 raycasts * how many units are coupled together or 1 raycast and some very complex and complicated math and calculations) or keep like a physical engine where the bogies still interact with the track and then make the cframe engine turn based on the bogies orientation but theres some physical issues and interaction issues.
I was thinking more of a wheel sensor thing that knows if its at a curve. Maybe raycasts (not very performant and i’d have to do one around where every bogie is so thats about 4 raycasts * how many units are coupled together or 1 raycast and some very complex and complicated math and calculations) or keep like a physical engine where the bogies still interact with the track and then make the cframe engine turn based on the bogies orientation but theres some physical issues and interaction issues.
For my train game, I was thinking much more abstractly, like just a marker of a train moving along a track similar to how modern railyard diagrams look (but hey, that’s my project). I would expect that working on the train chassis first would work better as its simpler.
Your Idea on getting the wheel to turn using a sensor is cool but I would argue that using a combined physics engine and CFrame train is risky as our Bogie might want to move sideways before the actual chassis and connection point move, potentially causing glitches.
I suppose its not impossible to do the combined physics engine, but its unconventional, maybe cool, we don’t have to worry about rotating the bogies at least that way.
How do you intend for the wheel sensor to detect if there is a curve? In my mind we could have a sensor part that touches another part on the ground telling the script that they have reached a curve, but I would like to see how you would do it.
Since you have already been working on a train game, is this meant to augment that or would this be a completely new project?
Yeah, I’m currently trying this wheel sensor method and it has issues when combined.
By wheel sensor it’s basically just a normal physics train and the bogies then bogies turn on a track it will just update the rotation of the train.
To be honest, it depends, if you’re wanting to work together on an entire train system then it would be a differen’t project or if you’re wanting to work on just a train chassis then that would be a differen’t project, and then once complete we could use that for our own train system projects.