top of page

Pulse Arcana: City Builder (WIP)

Ark: Survival Ascended Mod

Road Spawner Module Demo (Version 4)

Mod Info

Supports Cross-Platform

Supports Singleplayer and Multiplayer Modes

Tool Used:

Ark Dev Kit (UE 4.5/5.2)

Overview

Pulse Arcana: City Builder is a tool mod that allows players to import a city created in Fantasy Town Generator, set the buildings they created in ARK to the City according to the building type, and spawn the whole city on the ARK map. This mod is still a work in progress. 

My Role

As the Unreal Engine Game Developer of the Pulse Arcana projects, I was responsible for the entire development of City Builder mod.

Development of Road Spawner Module

Our goal is to enable players to spawn the city created in Fantasy Town Generator(FTG) with any rotation and scale, anywhere on the ARK map. Since the FTG doesn't account for varying terrain altitudes in the ARK map, we aimed to develop a system where the city's roads and buildings must dynamically adjust to fit the terrain. In this section, I will share the process of developing the Road Spawner module for the CityBuilder mod.

FTG-TD.png

FTG City Top-down view

0da3dcb35ad573feca21dbfa8298aed.png

version 1 spawned roads in ARK 

FTG is a website that allows users to create a city by configuring various attributes. Once a city is created, FTG generates a top-down view that includes buildings, roads, land, rivers, and other elements. Users can export the city's data, which includes the location information for buildings and roads.  In FTG, roads are represented as a series of line strings, providing the start and end positions for each segment. This data is essential for generating roads in ARK.

CSV.png

exported buildings & roads data (geojson -> csv -> DataTable)

The version 1 addresses the metrics transition issue from FTG to Unreal Engine 5. To ensure a consistent style with other ARK buildings, we decided to use floor structures, a type of item used for building floors in ARK, to construct the roads. Since the floor structure is cube-shaped, my plan is to spawn a series of floor structures side by side until they form a continuous road. So I created functions to calculate the distance between start and end positions to count the number of floor structures needed to construct the road, then compute the unit vector between floor structures to obtain the location of each floor structure. The algorithm used shown below:

unit vector = (endPos - startPos).normalized * length of the floor structure
structure location = previous structure location + unit vector

ARKFloorStructure.png

floor structure in ARK

RoadSpawnV1.png

version road spawn test

In the version 2, I focused on how to spawn roads that perfectly snap to any terrain, regardless of the road's direction. Initially, there were two plans: the first plan involved spawning the road as stairs when building on a slope; the second plan aimed to generate smooth roads on various terrains by adjusting the pitch rotation value of the road structure. The spawning algorithm in version 1 effectively created the stairs-style road when the terrain was not flat.

Stairs.png

stairs-style road on slope

However, I found that the second plan did not always generate smooth roads. When spawning the city, I added functions to ensure that the start and end positions of each road always snap to the ground, so the entire city would align properly with the terrain. When the terrain between road start and end position is a hill or pit, the road spawning strategy from the first version resulted in incorrect rotations because the calculation of the unit vector didn't account for the different snap conditions of every single structure.

SmoothRoadError.png

spawn road when there is a hill between start and end pos

SmoothRoadErrorPit.png

spawn road when there is a pit between start and end pos

SmoothRoad2.png

when the terrain between road start and end is a hill 

when the terrain between road start and end is a slope

In the version 3, to spawn a perfectly smooth road that snaps to any terrain, I redesigned the structure spawning algorithm. This new approach ensures that the top surfaces of the floor structure always connect seamlessly, resulting in a perfectly smooth appearance. Here is the process of how I developed this feature.

Problem Analysis
To spawn a smooth road, the top surface of each structure must connect to the previous one. This means that the spawning of each structure depends on the data from the preceding structure. Therefore, the version 1 spawning algorithm using unit vectors is inaccurate because each structure's spawning process must independently consider snap and surface connection issues. Consequently, the next structure's spawning can only begin once the previous one has been placed.

I began by drawing diagrams in Photoshop to analyze the problem and develop solutions based on the following rules:

1. The surfaces of the floor structures must connect seamlessly.
2. Each floor structure must align with the road's direction.
3. The structures must snap to the ground as accurately as possible.

Solution 1
Step 1. Connecting the Top Surface of Structures
To achieve a smooth connection, the top front edge of the next structure needs to overlap with the top back edge of the previous structure. This edge serves as the axis around which the next structure can rotate until it finds the desired spawn location.

Connecting the Top Surface of Structures

Solution 1 Diagram (Road Right View)

Step 2. Finding the Spawn Location of the Next Structure
According to the diagram, it's clear that distances 
d1=d2=d3=d4 , as these represent the radius within which the next structure can rotate. This radius r is a constant value, defined as the distance between the structure's pivot point and its top front edge center.
To ensure the next structure snaps to the ground, its world location(also the pivot point) should always snap on the ground. As the diagram and video below showed, I traced a vertical line from the vertice
C1 and moved it forward along the road's direction. This vertical line intersects with the ground, creating an impact point. When the distance between this impact point and the previous structure's top front edge center(C1) is approximately equal to the radius, then this impact point is the desired spawn location for the next structure.

detection.png

method to find next structure's location (Road Right View)

Step 3. Finding the Rotation of the Next Structure
The solution diagram indicates the desired rotation for the structure, but the specific values need to be calculated.
Here’s the approach I used:

Yaw and Roll
To maintain a smooth road, the roll value for each structure is kept at 0 or the structure's top surface will not connect.
The yaw value is determined by the direction of the road, which can be easily calculated from the given start and end positions.
Pitch Value Calculation
As shown in the below diagram, angle A2 is the pitch value we are looking for. We can easily see the vector relationship and angular relations through the diagram and help calculate the pitch value.

Vector Relationship:  vectors V1 and V2 lie in the same plane defined by the world up vector and the road direction. so the following angular relation is valid.
Angular Relations: The pitch value
A2 of the next structure can be derived from the relationship A2 = A3 - A1, where:

A1 is a constant value, determined by the structure pivot position(known) and the size of the floor structure in unreal(known)
A3 can be calculated using vectors V1 and V2,
V1 = (top front edge center pos of previous structure - Impact point of vertical line trace).normalized
V2 = world up vector (0,0,1)

AngleCalculation.png

Vector and Angular Relationship (Road Right View)

Step 4. Finding the Rotation of the First Structure of the Road
The first structure's location is set at the start position of the road, but its rotation needs to be calculated to ensure it is properly aligned with the ground and follows the road's direction. Here’s how to achieve this:

Yaw and Roll are the same as the calculation of next structure
Pitch Value Calculation
The first structure must also snap to the ground. To get the pitch value, I traced a vertical line through the start position and return the
Impact Normal from the hit results. Unlike the above Road Right View diagrams, this Impact Normal vector may not on the same plane with the world up vector and road direction as the diagrams shown below. 

impact normal not on the plane of world up vector and road direction

impact normal on same plane with world up vector and road direction

To determine the pitch angle (the angle by which the structure rotates in the direction of the road), I projected the impact normal onto the plane defined by the world up vector and the road direction. Then, I calculated the angle between this projection and the world up vector. The diagram below illustrates this process.

pitch.jpg

a : road direction
b: world up vector
c: impact normal
V1: projection of impact normal vector(c) onto world up vector(b)
V2: projection of impact normal vector(c) onto  road direction(a)
V3 = V1 +V2, representing the projection of the impact normal vector (c) onto the plane defined by the road direction vector (a) and the world up vector (b).
A1: represents the angle between V3 and world up vector(b) which is the pitch value we are looking for.

finding pitch value of first structure

Now we have all necessary data for the road structures and ready to spawn them in map!

Step 4. Spawn the Road
The road spawner will first place the initial structure, then proceed to spawn the remaining structures according to the previously discussed algorithm, until the entire road is constructed.

PIT.png

generated road spanning a pit

HILL.png

generated road traversing a hill

However, this version still has some problems. As you can see in the below screenshots, some parts of the road are not smooth, it is shaped like a wave instead.

Version3.png

Road Spawner Version 3

Obviously, for some special terrain conditions, the angle of the next structure is still not accurate. For example, for a gentle slope, if the first structure has an incorrect rotation, then the next one will be incorrect too as the angle is calculated based on the previous structure.

In version 4, I developed a new algorithm based on my discovery of how to construct roads using cube-shaped structures. Given the fixed size of the floor structure and the curved terrain, the challenge was to create a series of line segments that form a specific curve. By determining the position and rotation of each line segment, I could then calculate the necessary information (position and rotation) for each floor structure, preparing them for spawning. The diagrams below illustrate this solution process.

Version4-1.png

Line segments that forms the curve

Version4-2.png

Spawn the floor structures

Version4-3.png

Lift the spawned structure above the ground

Finally, this solution effectively addressed all the issues and performed well across all standard terrains. Compared to the previous version, this new algorithm significantly reduced the number of calculations and performed much better.

Solution2.png

RoadSpawner Version4 Demo

bottom of page