October 26, 2015

Smart trains!


One can now start and stop a train by clicking on it. Trains now spawn from the green boxes, and disappear into the red (yellow stations are there, though they don't mean anything yet). 

Also, implemented a collision-avoidance system. First, tried casting a ray (which is very like shooting a laser detector) ahead of the engine to detect if it was about to hit another train, and if so, stop by itself. But it was too unreliable. Next, I sent an empty gameObject ahead of the engine to collide with other trains. It behaved exactly like any other train car, but without the geometry. An invisible car zero, a "ghost car". The ghost car can safely hit another train and stop the real train behind it in time. This works a lot better. In cases of two ghost cars hitting each other, the train that has existed the longest gets the right of way. Seniority!

83 hours in.

October 14, 2015

Map Maker!


Got tired of moving the tracks around manually to test different scenarios. Knew I would have to make a tile-based level-editor eventually...  maybe someday, this will be a fun part of the game too: making one's own maps to play on. I use external XML files to store the saved maps and load them in when it's time to play. That was totally new to me, and took some learnin'.

Here, as a key example, is a line of code that collects the contents of any tags named "T" in the whole XML document and puts them into an ordered list called "types". My program then refers to the list when deciding what track to put at what square. Handy!
string[] types = xmlDoc.Descendants("T").Select(element => element.Value).ToArray();

About 400 lines of code for the map maker, 200 for the train motion so far. As we learned on Starbounder, working out a good user interface is much harder than the actual game.

53 hours in.

October 06, 2015

Cars!


Box now replaced with basic engine, hopper, and caboose models. Rather than check ahead for itself, cars behind the engine do whatever the car in front of it did, but delayed. Only the engine decides where to go, so the train doesn't split if you switch tracks in the middle of it. The white "station" box at the top can spawn a train with a random number of cars and send it down the track.

22 hours in.

October 02, 2015

Motion!



Instead of plotting the box's path with complicated trigonometry equations I don't know, using a finicky physics simulation to stay on track, or using costly raycasts to read the rails every frame; this rectangle is simply animating along a local motion path. When the end of a path is reached, the "train" looks ahead to see where the next track section is, centers itself on the new section, and starts a local animation clip (either straight right or left depending on the type of track). If all goes right, the moment it jumps to the new track section should be unnoticeable. It then animates along that path until the end is reached and the process repeats. Let me see if I can illustrate this idea. I know words probably won't do it...

Cars will loop their animation locally if there is no next track section...


...if there is, however, the car moves and re-orients itself to the next track section before re-playing the animation. The jump is too fast for the player to see (here, I have made it visible with the green indicator), and the motion of the car looks seamless.

16 hours in.