Setting Up An Endless Runner
To begin making an endless runner, the movement and camera need to be set up. For this, we first need to remove the option for the player to control the forwards/backwards movement and instead have the speed set to increase using the event tick node.
Detach the forwards/backwards movement from the player input in the character blueprint and move it to its own section.
Then use the event tick node and add it to the movement input, making sure you have it so that, with each tick, a +1 is being added to the movement input to make sure the player is always moving.
In terms of camera set up, delete all camera controls since the player should not be allowed to move the camera. Then adjust the camera location to be further back and higher up from the player for that typical endless runner view.
The next thing an endless runner prototype needs is the level layout. To begin making this, we need to create a master tile. A master tile is used to create the endless part of the endless runner as it act as the floor, spawning in each time the player reaches the end of the previous one.
For this, we need to use three blueprints: the player character's, the player gamemode's and a new actor which will be our master tile.
The master tile should consist of a box which will act as our floor, a box collision which will trigger the spawn event and an arrow to mark where the next tile will need to go.
The first step of coding the master tile is to have a way to trigger the event. This is done by using on component begin overlap which, when triggered by the character, will cast to the gamemode.
Now we need to create the actual event in the gamemode which is done by using a function. We use a function so that it can be called on in the future rather than recreating the code if we need to reuse it. This event spawns a new master tile actor, setting it to a new location based off of the arrow's location from earlier.
Next is to add this function to the gamemode's event graph so that we can decide when this function should be active and how is should be implemented. In the event graph, we use event beginplay as it means the function will be active from the start. We then need to use a for loop with a 0-5 index. This is done so that the function will cycle through spawning 6 tiles, making the floor far enough out to look like a path.
Now that the event has been made, we can add it to the master tile script so that it can trigger the event using the collision. Also add a delay and destroy actor node so that, when running for long periods of time, the performance stays solid.
When testing, I found that there is a random secondary platform spawning at the start of the game. This was because I had placed a master tile in the world assuming that that was necessary when the spawn event was already doing that on its own. Deleting the master tile I had placed fixed this.
Next was lane switching. Most 3D endless runners use some form of lane switching and so I want to at least add it to the prototype even if I change my mind later. For this we need to add some more arrows to the master tile, one for each lane so that we know the location of the y axis.
Now we disconnect the left right movement input in the character.
Now, before we start adding movement, we need three new variables. The first two, labelled Lane and New Lane, will be integers. The third, named Lane Y, will be a float array which will have three elements consisting of the three arrows Y location.
Now we can set up movement using the A and D keys which will, when pressed, set the new lane variable to be the lane variable plus or minus 1 with a limit of 0 and 2 (this is because the array only uses indexes 0-2). This will be used to pick which y location we need from the array.
We then have those set the actor location. For the new location we first split the struct pin as we only need to change the y. This change will be done by getting the new lanes integer out of the array. The new location is then set to the Lane.
While this does work, it looks quite unfinished and so the next step is to smooth out the lane switching so that the character no longer teleports. For this we need to add some nodes in between the previous code, starting with a timeline which will be before the set player location node.
This timeline then needs to be set up to have a 0.1 length with nodes to change the value from 0 to 1 in that time. We can then have the set lane end nodes moved to the timeline.
Then we have to set up a lerp so that the location fully knows where the character is coming from and going to instead of just relying on numbers. This is then plugged into the new location y.
After testing, the player's animation seems to be backwards and so I have adjusted the timeline to go from 1 to 0 instead of 0 to 1.
For this game to properly count as a game, we need some form of score system. This will be done in the master tile as a function since the score will be related to how many tiles the player reaches. Before we make the functions code, however, we need to add a few variables to the gamemode those being score, score multiplier and collectables.
Now we can have the function cast to the gamemode, find the score variables, have the score multiplier (which should have a default of 1) multiply by 10 and add to the score before setting the score as the new number. Add a print string to test.
This function is then added to the tiles' event graph.
Now, as a bonus score, we can create collectibles. This requires a new collectibles actor as well as some spawning mechanics added to the master tile and the collectibles variable from the gamemode. The collectibles actor should have a sphere that is at z location 150 so that it spawns a bit further back.
Now, in the event graph, we need it so that the collectable casts to the gamemode upon overlap with the character. This will let us reference the collectibles and score multiplier variables.
We use these references to add the score multiplier to the collectable total as well. The collectible is then destroyed.
Next is getting them to spawn on the three lanes. This is done by adding a float array to the master tile with the same index as the array for the character switching lanes. This array is then used alongside a random integer to spawn collectibles randomly across the y axis.
After testing and finding out that they were only spawning in the left lane, I realised that the random integer had been left at a max of 0, only letting the random lane be the first lane.












