This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

Train movement implementation

GlebastikGlebastik Posts: 5Member

Hello there!
I'm trying to make some kind of train simulator on Godot, and I'm wondering how to implement the most important thing. The movement on rails.
I didn't want to use just a spline and PathFollow node at first - this simple solution is suitable for decorations only.
I tried using real train physics but quickly abandoned this because of too much inpredictability and unstability. Then I began to invent "crutches" like using a VehicleBody and VehicleWheels with auxilary collisions on the inner side of the rail, adopting the RaycastVehicle by Tobalotion, etc. After several defeats with physics I decided to return to splines. Will need to modify the original Path and PathFollow nodes, I think, but I have not enough coding skills to do it.

Now I'll try to explain.

How is the train sets in motion? Traction motors rotate the wheels that are fixed to the trolley. The body of the locomotive rests on trolleys via the pivot, so the trolley pulls the body, roughly speaking. The locomotive and the cars are connected by the couplers, so the locomotive pulls the body of the car that rests on its own trolleys and pulls them along.
I want to implement the same system, but PathFollow will be applied as an axis on which the trolley is mounted. The node will be just a helper to hold the trolley and rotate it in the right direction. The rest will be done with bones, joints and physics. The node itself should move along the spline freely or under the influence of any external forces. I think I need to calculate this forces and change the Offset parameter via code. I'll be gratefull if you give me an example of that code, if possible.

Also there is another question about the dynamically changing Path. I imagine that the railroad consists of some amount of splines (Curve3D). Each curve represents a railway section. This can be used for implementation of a signalling system and turnouts. So our Path should load the curves one by one as it moves. And it should know whether there will be a diverging on the next turnout (which represents two or more converging curves). Is that even feasible? If so, then I ask for help with code.

Thanks in advance.

Answers

  • cyberealitycybereality Posts: 928Moderator

    I'm not experienced with this yet, but it sounds like a cool project. Anyhow, welcome to the forum!

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.