Well, If say directly to the question, logic have place even in games... It needs two leading units, like trains have. Here is clearly first car going back trough others and then turns over the entire tram-train. Just pure mechanics as I can say. And if trams doesn't support that, we can't do anything than use standard tram railways. It is working as needed but only for such car, and result can't be achieved without moving other car to be 1st in train.
Hope it's possible to emulate, they have direct bonding to their classes, not very familiar with code, but you may rewrite this to represent train (?) and this thing will use both motor cars on bidirectional track.... But it will not work as tram, if even will work at all.