+1 vote

I would like to know what would be the best, simplest way to make a train follow dynamic tracks.

I've got train assets (wagons) and tracks assets prepared to build GridMap (square segments). I would like to build a map using those track parts and run a train on it, that would go where the railroad is laying.

Rail Assets

Could you point me in the right direction?

in Engine by (139 points)

I think i would use paths.
Start- and endpoint at the edges of your mesh (whee the train goes in/out). Then let the Train follow that path. If it is at the end, find the next tile, and use the next path to follow.

OK, sound good. Can you give me some example how to add points from GDScript? I can travel in straight line using add_point() but if I try to make a smooth turn I jump all over the place.

This documentation is unclear for me. What's "in" and "out" exactly?

Why do you want to code this?
Isn't it much easier to create a node/scene for every possible tile and place the path manually?
(Sorry, i have no clue about your project-structe, node-tree, etc. and i never had a similar problem before :P)

Another possible way would be a math-function, that know where to place your train, depending on its progress through the tile. That might be more accurate, but you have to write a function for every possible way in each tile...

@all: any suggestions? please?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.