Make a railroad track

Hi there,

what is the most best way, to make a top down rail road track where on can go a train.

I would use a few different objects for the track. One tiled sprite object for vertical track, another tiled sprite object for horizontal track, then make a few regular sprite objects for turns. Add all of the objects into an object group called for example “tracks”

Next to make a train object move along the track, i would probably use the tween behavior. You can tween the x position, and tween the y position to move from one end of a track object to the other end. Once tween is “finished” you can do the next tween for the next track. Its probably the easiest to go into the track objects and define custom “points” in the sprite to make it easy to find the position to move to (so, create a “leftside” point and a “rightside” point, then you can tween position using these points for each track object)

1 Like

I just tried it and actually its difficult to get the speed consistent using tween.

Instead, I used a single track object, and instead rotated it to make the track turn. Then, I added an event to check for train center point within track object to select the track the train is standing on, and apply a force on train in the direction equal to the angle of the track. This makes the train move in the direction the track is rotated in

I’m not sure how to get a smooth turn using this method though, but it was a lot easier


I tried the tween as well. I used the distance from the train car to the next corner piece and multipled it by 10. The greater the distance, the longer the duration.

It works for 1 train car but additional cars get out of sync when they turn because the car turning is moving slower than the cars in a straight away.

Tweening would work for the engine but maybe not trailing cars.

1 Like

The shadow clone extension could be used for the cars maybe. The shadow clone extension would make the cars follow the movements of the train engine automatically according to exactly how it moves, but with a delay

1 Like

Something like paths are not yet available in GDevelop?

There is an extension in progress:

1 Like

That extension sounds great!

Here is an example of my solution:


This is amazing! — This shoud be part of the offical release of GDevelop.

How can I create the SVG coordinates?
I’ve tried Inkscape and online editors, but the result is always a mess or incomplete.

Maybe the editors use commands that the extension doesn’t know? In this example h and v.

Not entirely wrong but hm.
Is it also possible in the future that the size will retain?
Otherwise it is almost impossible that the path and graphics in the game fit together (hit the road or rail network).

Yes, I didn’t handle h and v commands. Thanks for reporting this. I’ll make sure to add it for the release version.

Okay :slight_smile:
I don’t know if you’ve already planned it, but Pause and Resume actions like available for Tweens would also be very, very helpful.

I uploaded a new version that fixes the L and V commands and adds a 2nd behavior that uses acceleration instead of tweens.
The example contains a new scene with a train that follows a closed path.