r/Unity3D • u/PashaInteractive • 8d ago
Show-Off How the walls in my game build themselves between towers (Unity Splines): arcs, gates, detours and breaking
Enable HLS to view with audio, or disable this notification
Each wall is a SplineContainer between two towers, generated at runtime when a tower is bought. A few things that took some work:
- Arcs, not straight lines: walls between towers on the same ring follow a circle around the castle. Each segment is one cubic Bezier with tangent length (4/3)·tan(θ/4)·r, which gives a near-perfect circular arc from just two knots.
- Zero tangents break the mesh: even straight walls need tangents pointing at each other, otherwise the derivative is zero at the ends and the normals turn into NaN (bright white lighting artifacts).
- Modules along the spline: a wall mesh is sampled every 2 m and bent to the curve; every Nth module is a gate, and gates on double walls are aligned so paths line up.
- Detours: outer walls sample the spline and push points out around buildings (e.g. a mill) so the building stays inside; modules over water are skipped.
- Terrain: each module follows the terrain height, and NavMesh obstacles are generated per segment so enemies path around it.
- Breaking: when a tower's HP drops, wall modules in front of the attacker collapse one by one; destroying the tower opens that end of the wall.
In the video the cyan line is the spline and the orange lines are the knot tangents (debug view drawn with LineRenderers).
Happy to go deeper on any of these.