Advanced Mechanics Design

Unity Programming Module

Advanced Mechanics design is a 2nd Year module I was enrolled on at Staffordshire University.
For this module there were 3 focusses that I would have to complete;

  • Splines
  • Tank Controller
  • Wave Spawner (Unity ECS)
  • Mesh Lofting

    To Procedurally generate meshes first we need to know what a mesh consists of.
    A mesh is a combination of vertexes connected using edges, these edges can be used to create 3 types of faces, Tris (3 Edges to a face), Quads (4 Edges to a face) or N-Gons (5+ edges to a face).
    A mesh has face normals which can only be viewed from one side unless backface culling is enabled on the mesh.
    A UV Map is the faces of a 3D object flattened into a 2d view, in which coordinates on the uv, map a texture onto a face.

    To create our objects we crete vertexes. For this cube I have 24 Vertecies as it allows for hard edges and simple maths when creating the object.
    With 3 of the vertecies a Tri Face is created, this is then calculated and placed in the world.

    Editor Handles

    To create multiple mesh lofted objects I tweaked the code slightly to loop through a vector 3 for the number of cubes adding an offset after each one. Within the code I also tweaked it so the shapes can alter scale instead of a fixed value which will allow me to make an editor handle.
    The result is being able to create my rail sleepers which I use later for spline mesh generator project, additionally I could have used this for my rails as I could have stretched cubes to create the length of the rail and set the number of Z chunks to 2 with an offset of about 4 to create the second set of tracks.
    All I needed to do afterwards was curve the mesh along a spline.

    Spline Mesh Lofting & Animation

    Using a spline I achieved creating a procedural railway which adapts to terrain around it, there are multiple values that can be adjusted as well as an animated train that follows the spline. In creating the rails I wanted the vertices to be as one long mesh which subsequently has a continuous UV Mesh becuase it would only use one flat colour. I generate 4 vertices and create faces from the most recent set of vertex data to the previous which allowed for me to work backwards from the newest.
    Once it reached the end I used a condition to generate the final piece of mesh, if the Spline did not loop it would close off the rails with a final face, if it did, it woud generate one more set of faces connecting to the first vertecies.

    I then would refactor some code from the Cube Generator to create the sleepers which connect the middle of the track, this was from the cube code and it worked well, I would just have to multiply the Width and height by the right and forward vectors to get the vertex point.
    I would then move onto creating a pillar support system which uses data from the world to generate the mesh and linking all the scripts together so I can control the rail generation from one centre point rather than each script, this helps keep values unified across the generation. For the pillar supports I would raycast down and check the distance, if it was greater than a minimum value it would generate a pilar

    Designs

    Below are the designs for each tank force such as suspension, friction/drag, steering and drive forces

    Demo Videos

    Parsing the TomBen Format

    The TomBen format is a format that given to us as the final part of the AMD module, in this we would have to create a wave spawner that uses these values in an ECS system.
    The main problem with this file format is that it required a custom parser to read the values, I decided to make a parser for it using Regular Expressions, this way I could loop through the waves and clusters to get the number of desired units to spawn and when to spawn them

    Tom Ben Format

    Sorting Blocks into Lists

    Reading Units from Waves

    Wave Spawning

    Here are the final results of the wave spawner, this was an estimated 2 weeks for this section of the module. One video of the parsing, and another using the Entity Component System
    at a later point, possibly after graduation I would like to investigate the unity ECS system further as it has lots of capability when creating a game which needs multiple of the same entity.

    GitHub Repo