Platform:
-Unity Game Engine
Engine/Language:
-Unity (C#)
Project:
-Individual project,
-Unity Tool
Race Track Generator is a tool for the Unity game engine. Its objective is to aid developers in creating unique race tracks using procedural generation. One advantage of a tool like this could be to cut down on development time on creating race tracks.
To generate the race track there are three main steps which takes place. The first is a Voronoi diagram is generated.
A Voronoi diagram is a diagram which has been portioned into cellar regions where all the points within each region are closers to its defining point than any other point [1].
There were a few noticeable challenges that occurred when creating this tool. One of them was finding the outer edge of all the cells which were selected to form the race track. This was an issue as each cell in the Voronoi diagram stored its own edges in a linked list. This prohibited me from just checking if two cells had the same edge. As the edges where unique to each cell. The solution which I came up with was to loop though all the edges finding any edge that shared the same centre position. If more than one edge shared the same centre position, then that edge was not added to the outer edge list. This removed any edge which was not on the outer edge.
////// Return a list of vEdge for the outer edges /// of a list of cells /// /// </param> ///private List<vEdge> GetOuterEdge(List<Cell> a_cells) { //get all the edge centers from all the cells within a_cells (a_cells is the list of out selected cells) List<EdgeCenter> center = GetAllEdgeCenters(a_cells); //Create a new List of vEdges. This List will store all the valid edges List<vEdge> outerEdges = new List<vEdge>(); for (int i = 0; i < center.Count; i++) { //get the first edge center EdgeCenter firstEdgeCenter = center[i]; //Track how many positions are the same int sameCount = 0; //Loop though all the edge centers for (int j = 0; j < center.Count; j++) { //get another edgecenter EdgeCenter secondEdgeCenter = center[j]; //if i and j are not equal (this makes sure we do not evaluate the same edge center) if (i != j) { //if the positions are the same (edges are overlapping. Edges are not on the out side) if (firstEdgeCenter.position == secondEdgeCenter.position) { //incerment sameCount sameCount += 1; } } } //if there are no other edge's which match our current edge //add our current edge to outerEdges if (sameCount == 0) { outerEdges.Add(firstEdgeCenter.edge); } else { //Draw the line which is overlapping //Debug.DrawLine(firstEdgeCenter.edge.v0.Site.Vector3(), firstEdgeCenter.edge.v1.Site.Vector3(), Color.red, float.MaxValue); } } //Return outerEdges return outerEdges; }
If you have any question or suggests about this project or any other project please do not hesitate to contract me
[1] - Worley, S. (1996). A cellular texture basis function. Proceedings of the 23rd annual conference on Computer graphics and interactive techniques - SIGGRAPH ‘96. [online]