This blog will go through some of the major milestones of the tool's creation.
The aim of this asset tool is to help the development of games with rail networks and
to provide to tools to setup a train and route with relative ease.
Prototyping
I started with a prototype for the spline editor using
Processing 4.
This allowed me to learn how bezier curves work, how to manipulate them, and how to
connect and disconnect seperate curves before having to do it in Unity.
The design of this UI will not effect the design of the final product as this is just
a prototype in a different program.
Unity Tool
Curve Editor
The most important part of the tool is creating the tracks. I used Unity handles to
control where the anchor and control points were. I coloured the anchor points
differently to the control points so that they could be distinguished. The colours and
sizes of the points and the curves can be changed via the preferences window if the
developer doesn't like the colours or is working at a larger scale.
Each point can also be selected using shift and left-click showing its properties in
the inspector. This allows the developer to edit the values directly such as setting
the position and rotation of an anchor.
This inspector also includes setting to constrain the position of the node while it
is being moved, locking it to 1 or more axis.
There are three difference modes of interaction: move and adding; splitting; and
removing. This was the smallest amount of modes I could make while only using shift and
ctrl click. This means that the developer has to change modes less. I didn't combine
split and remove because I wanted removing to be a delibrate action. Depending on the
mode, the track will be shown differently. For example, if remove mode is enabled,
the control points are hidden as they can not be removed. If split mode is enabled,
a line will be drawn to the closest point on a curve showing where it will be split.
Rail Network
This is the script that generates the rail network for path-finding to work. The only
thing a developer has to do is add the RailwayNetworkBehaviour to the same GameObject
as the RailwayManager.
Behind the scenes, it uses the path data to generate 2 nodes at each anchor point and
then connects the neighbours together. It then uses the A* algorithm to generate a
route the train can follow. Part of the path-finding algorthm makes sure that the
train can't go back up a junction effectively cutting a corner.
Bogies and Trains
In order for an object to ride the track, the developer needs to add a Bogie script
to it and attach the RailwayNetworkBehaviour. If they have multiple carriages,
multiple bogies can be linked together. They stay the same distance appart on the
track as they were initially set up, which avoid trying to guess the distance they
need to be apart. For an object ride 2 bogies, a Train script can be used which
controls the position and rotation based on the connected bogies.
Waypoints, Stations, and Routing Tables
For a train to go around a track in a certain way, waypoints and stations should be
used. There are just objects with the Waypoint or Station script on them and they
can be moved to connect to any anchor point on a track. They both have different use
cases. Waypoints are used to guide a train along a certain path, for eample if there
is more than one way to get somewhere. Stations will stop the train and can be used to
hold it there until a method is called or after a certain amount of time.
This information is provided via a routing table asset and should be applied to the
lead bogie. Waypoints and stations are selected based on their name in the scene, and
the names must be unique.
Finale
Evaluation
In it's current form, the asset tool may have the ability to compete with assets such
as
Dreamteck Splines.
I believe this because my tool has a simplier setup for train junctions and train AI.
As a general spline tool, Dreamteck Splines is still better and has more functionally
outside railways and trains.
Compared with
Track Roller Coaster Rail Keypoint Basic Editor
and
Tracks and Rails,
these assets have physics-based cart movement and so would be better for rollercoaster
type settings. My asset has the ability to to create rollercoaster tracks, and a
developer could make their own bogie script to have momentum on the track, but this is
not provided as part of the tool. While Tracks and Rails has the ability to change
the track at runtime, creating pseudo-junctions, it does not provide a form of
path-finding. Train Controller (Railroad System) v3.4,
is the most direct competitor to my asset and has many features mine does not. These
include: physics-based trains, event zones, baking meshes, and terrain deformation.
What mine does beat it on is simplicity. Creating junctions and routes is easy and
relatively simple to understand and thanks to the path-finding, adding extra track
shouldn't effect a trains route. I think it does display the route better than mine
does.
In terms of cost to develop, it cost me nothing as I'm a university student at home.
If I did have to pay myself during that time, it took about 7 weeks to develop with
some weeks busier than others. averaging about 24 hours per week, that results in
168 hours of work. Assuming I'd pay myself £16/h, that's £2688. The tool still needs
work but if I were to sell it on the
Unity Asset Store
as is, similar assets have about 26 reviews, 420 favourites, and cost about £42. I
may charge about £40 which means I would need about 68 purchases to make back what it
would've cost to develop the tool.
Reflection
Overall, I think the asset tool is functional and usable in a project with some small
customisation. Creating the prototype was helpful for understanding how to manipulate
the curve and junctions but didn't help with working out how to get the normals on the
curves.
Saving the track data was initially a struggle as Unity can only save serialized
data. Unity's handle system was also a struggle to deal with at first as the control
IDs are generated each frame so I had to cache them at the start of every frame.
Adding the bogies and trains where easier than I expected and after some tweeks,
worked as expected.
While developing this tool, I also created two other tools which ended up helping
with the development of this one.
If I had started development earlier, there may be more features to this tool or the
code would be more polished but with the time I had, I think I made a good asset tool
that I can use in future projects.