Page 1 of 2
Train Factory
Posted: 30 Jan 2016, 19:28
by Parzival
Hello!
This is my first time posting on the SpringRTS dev forums, I usually post on ZK ones.
Like the title of my post implies, I'm trying to figure out how to build a train factory. I have most of the movement concept down (Not going to use rails, Just gonna put a lot of movement restrictions on that way it requires terraforming)
The thread I've posted all of my stuff in is here:
http://zero-k.info/Forum/Thread/20224
Also been using this guys ideas:
viewtopic.php?t=17137&start=20
The main thing i'm wondering about is how to attach the trains to one another. Is there a feature on unit behaviour that makes units do that?
Re: Train Factory
Posted: 30 Jan 2016, 19:33
by FLOZi
It will probably be worth using dev engine so you can utilise new attachment / transport features:
viewtopic.php?f=12&t=33843
Re: Train Factory
Posted: 30 Jan 2016, 20:34
by Parzival
So maybe use attachunit?
Re: Train Factory
Posted: 30 Jan 2016, 21:55
by FLOZi
Certainly will be the best way of attaching them.
Also, sketchup is terrible for modelling for Spring IMO.
Re: Train Factory
Posted: 30 Jan 2016, 22:49
by 8611z
Imo use the MoveCtrl functions to set positions of the waggons, like you would in a snake game.
https://www.google.de/?gws_rd=ssl#q=gam ... rial+snake
Spring's attach/transport functions do not seem useful for trains.
Assuming you have the locomotive and each waggon as a seperate unit and attach them like this:
locomotive

waggon1

waggon2

waggon3
Now the locomotive begins a turn and rotates. All the waggons insantly follow the motion and rotate on a arc with center on the locomotive. Train waggons should only begin to turn once they are on the bent part of track. In spring1944 you can test with the trucks and guns how units attached to each others behave.

The connection is rigid and so the towed gun-unit swings out behind the truck like a stick.
Looks acceptable for a short truck-trailer comb but unuseful for a longer train.
Assuming you have the tracks as units that "transport" the locomotive and waggons then that you have to deal with lots of annoying extra annoyances, and you will still need some logic to keep the waggons attached to each other.
Re: Train Factory
Posted: 30 Jan 2016, 23:46
by PicassoCT
FLOZi wrote:Certainly will be the best way of attaching them.
Also, sketchup is terrible for modelling for Spring IMO.
I wonder why people use this simple to use tools, instead of all the fancy - stuff. Surely is the peoples fault, definitely not that my perspective is biased by years of exp. Never meet them halfway, by creating for example a shader that would decently texture a sketchup created unit. Filthy casuals.
Regarding the train. You can make the wagons, units of their own, following the motherunit, with motion ctrl only kicking in when the distance gets to big.
You could fake it, by having two models for turns, adjusting the wagons axis and height by finding the piecepositions height on the map and basically program a small physicsim in lua. This road is tempting and expensive and very complicated.
The Move restriction idea does not produce really pretty results... units moving along, snap around the corners in 90° .
Finally you can combine these. Have a unit, that is one unit as long as its standing still, and turns into several once going.
Have fun..tschoo.. tschoooo
Re: Train Factory
Posted: 31 Jan 2016, 01:55
by FLOZi
I disagree. S44 truck & gun is a
single unit, not attached. Anyway with atachments you can rotate the attachment piece to turn each part... it is the way to go. Using movectrl every frame is less reliable in my experience.
Re: Train Factory
Posted: 31 Jan 2016, 02:07
by hokomoko
MoveCtrl is complex, so many bad and weird things can happen from conflicts and happy collisions with other parts of the code.
Having a unit attached to a unit attached to a unit... where every attach point is a free invisible piece may be a nice way to implement a train with some silly script updating the attach point piece in absolute rather than model coordinates to rotate/follow the transporter.
Re: Train Factory
Posted: 31 Jan 2016, 02:57
by 8611z
Some of the guns in S1944 do work via the transport-methode. Whether the gif shows a single unit that deploys via "morph" gadget or or two "loaded" units does not really matter: The effect looks excactly the same and so shows the problem just as well.
I am not sure sure if moving & rotating the attach-pieces helps:
No matter how you rotate the attach-points between waggons, the train as whole will always travel in the same direction.
In a real train waggons can travel in different directions.
The rotation works different, the movement works different, it would be so much "adjusting" the attach-pieces that one might as well not attachUnit anything.
Basically it would be two steps:
1) Undoing all the movement of the previous waggon
2) Doing the movement you actually want
With moveCtrl first step is not nessecary.
some silly script updating the attach point piece in absolute rather than model coordinates
At that point there is not much difference left to using SetUnitPosition()
moveCtrl stuff works very nice. It has been used for jumpjets, making non-fly-stuff fly, conveyor belts, underground digging units, ...
Re: Train Factory
Posted: 31 Jan 2016, 10:33
by PicassoCT
Ive spend half a year on/off lua-porting the nehe-rope physics. Rope == train.
And its funny.
Inefficient.
Not working at all.
But funny.
Re: Train Factory
Posted: 31 Jan 2016, 22:46
by Parzival
Having a unit attached to a unit attached to a unit... where every attach point is a free invisible piece may be a nice way to implement a train with some silly script updating the attach point piece in absolute rather than model coordinates to rotate/follow the transporter.
My idea exactly. I wanted to place a node on the train model. Would that work with attachments?
Re: Train Factory
Posted: 31 Jan 2016, 23:14
by FLOZi
8611z wrote:Some of the guns in S1944 do work via the transport-methode. Whether the gif shows a single unit that deploys via "morph" gadget or or two "loaded" units does not really matter: The effect looks excactly the same and so shows the problem just as well.
Perhaps but those s44 units make no attempt to address the problem.
I am not sure sure if moving & rotating the attach-pieces helps:
No matter how you rotate the attach-points between waggons, the train as whole will always travel in the same direction.
In a real train waggons can travel in different directions.
The rotation works different, the movement works different, it would be so much "adjusting" the attach-pieces that one might as well not attachUnit anything.
Basically it would be two steps:
1) Undoing all the movement of the previous waggon
2) Doing the movement you actually want
With moveCtrl first step is not nessecary.
some silly script updating the attach point piece in absolute rather than model coordinates
At that point there is not much difference left to using SetUnitPosition()
moveCtrl stuff works very nice. It has been used for jumpjets, making non-fly-stuff fly, conveyor belts, underground digging units, ...
You may be right. I guess it depends on a. the length of the train and b. most critically, if curved tracks are required and how gently they curve.
Re: Train Factory
Posted: 01 Feb 2016, 03:35
by Kloot
This should really not break anyone's mental budget...
1) define your track as a list of connected (pos, dir, length) segments
2) define your train as a list of units ([0]=head, [1]=first wagon, etc) all moving at the same speed
3) for all units in train: find track segment based on position, set direction to match, move along track
4) goto 3
Like knorke said, composite transporters or rope physics nonsense are *not* needed, basic MoveCtrl will do.
If you want to be fancy, use splines for curved segments, or allow each wagon to have a front and rear bogie (appropriately offset along the z-axis) and interpolate direction whenever the front bogie is on a different part of track than the rear. If not, just snap it for TTD-style trains.
Re: Train Factory
Posted: 01 Feb 2016, 10:43
by hokomoko
The question is about trains not on tracks, of course if you have tracks situation is considerably simpler.
Re: Train Factory
Posted: 01 Feb 2016, 11:47
by Silentwings
I have no idea what a "train without tracks" is supposed to do.
Re: Train Factory
Posted: 01 Feb 2016, 11:56
by hokomoko
I figured it's like a bunch of kids doing a human train
Re: Train Factory
Posted: 01 Feb 2016, 12:15
by Kloot
trains not on tracks
That seems even more basic, ever played Snake?
Whatever movement carriage
i executes, carriage
i+1 repeats (length/speed) frames later for all
i.
edit@below: nah, knorke beat both of us ("use the MoveCtrl functions to set positions of the waggons, like you would in a snake game")
Re: Train Factory
Posted: 01 Feb 2016, 12:15
by gajop

EDIT: Kloot beat me to it

Re: Train Factory
Posted: 05 Feb 2016, 16:41
by code_man
Trains in spring would be awsome, i loved them in tibsun, if they had gameplay mechanics that would be so rad.
Re: Train Factory
Posted: 07 Feb 2016, 20:05
by Parzival
The problem with tracks is that to use them, they have to be built as units. Apparently I can't use typemap (Area 17 fires anyone?) for tracks.
