I love the idea of having cliffside villages and towns crammed in the top of mountain peaks so I created the landscape of Tribal to be a bit more dramatic (it is still placeholder at the moment). With higher cliffs, my ladder system seemed out of date and less useful as the need to cross larger gaps and higher cliffs became more necessary. As a result, I decided to create a dynamic bridge and stair creation system. We'll talk about the stairs today.
The idea is you can build stairs built into cliff walls to get to higher or lower locations.
So how did I accomplish this? I'll go over the basic idea and you can create your own version. First of all, as I have a building placement system already functional, when you place the first half of the bridge, it creates the second half to be placed.
Each half uses the same code to set its location to the mouse courser on tick below:
The first commented section traces from the mouse to the ground and breaks the hit.
The second commented section adjusts the hit to snap to a grid I have setup for my game.
The last little section adjusts the pad's rotation based on the impact normal. What this means is that the rotation automatically adjusts to face away from the cliffside. This took me a long while to figure out how to do and I went through a few iterations but this an is exceedingly simple way to accomplish that.
I also have a code for when you click, it places the pad permanently. So that's it for pad placement!
Then a spline is created between the two.
This spline is the steps themselves between two pads. There's quite a bit of code running on tick including quite a few "ForEachLoop" nodes which I know is bad. I'm not sure a good way around this, but it seems to work fine as there's only one of these running at any given time.
Put in basic terms, what this does is check if there are as many spline segments as the distance between the two pads multiplied by the size of the spline segments. If it's wrong, all the spline segments get deleted, and re-generated based on that distance. Then regardless of whether the spline's length is correct or not, each segment's starting AND ending location AND tangent is adjusted to face the right way and connect to one another to match the movement of the mouse on tick. I know it's a lot! but take things step by step and you can figure out a system for you.
With just this, you can create a bridge that grows dynamically from a starting location to the mouse's location!
Next step is to create a slight offset so the spline doesn't start and end at the CENTER of the pads but at the edge of them. This is of course depends on what you are actually trying to accomplish.
On tick (again!) I add a simple 50 units to the location of the spline start AND end in the direction of each pad facing each other.
It seems like a slight adjustment but it really helps with believably. (And also helps with nav-mesh creation later). I also ignored the Z direction because these steps are meant to be built only on the XY planes.
This is the result:
You can see the edges of the steps spline always seems to snap to the correct edge of the pad. I really like the way that worked out.
Finally, I created a check to see if there is a cliff at every step along the path of the spline. This is so you can't build the steps in thin air. Of course this only applies to this specific inrastructure type, but I thought I'd add the code here anyways.
Again this uses forward vector and runs a simple line trace to see if it hits anything visible along each point in the spline.
And that's it!
I had a bit of trouble getting my stairs to go around edges and around corners of the tall mountains and I thought it would be really cool to have the stairs wrap tall pillars in the landscape so I added some more code to place a middle pad and stretch stairs between the two. It was exceedingly complicated to figure out but I finally cracked it for quite a cool effect.
If you have any questions or comments please leave them below and I'd be happy to answer them.
Also a quick note that took me a while to figure out. To add a material to a spline, you have to check a box in the material that says "used with spline meshes" otherwise it uses the default material.
I create, design and develop video games I'm interested in playing.
The Fire System
Melee and Ranged Units
Weather and "Seasons"
Ladders and Elevation
Animating 2D units in a 3D world
Setting the Theme
Setting the Focus