Transition between splines

Hello everyone,
I’m working on an endless runner game and I’m trying to implement a functionality which keeps the player in lane along the spawned floor tiles. I want to have 3 lanes in which the player can run along, so the simplest way to implement something like this would be to to move the player a constant amount to the left when presing a button to move left if he isn’t already on the left lane and the same for the right. However this would only work if my game has straight floor tiles. But I want to have slightly curved floor tiles, too without getting the player walk out of the lane. For example:
SubwaySurfer

The only solution which I could think of was to do it with a spline.
I have seen a tutorial how to make the player following a spline Spline locked Sidescroller and I think I would be able to make it possible to let the player move left and right along the spline, but the problem is since the endless runner game has a random generated course there cannot be one long spline along the course, but many short splines. In fact one spline for each floor tile and the problem is that I don’t know how to connect them. I hope someone can help me solving this problem or knows probably a even easier solution

Thanks in advance

I’d turn your floor tiles into blueprint actors containing the geometry (floor tiles, randomize-able obstacles etc), plus a spline component (for the character’s root to follow along with as he’s running) and some variables like a reference to the next track segment that’s chosen/spawned in.

You can put sockets on static meshes in UE4, so I’d make sure each piece/tile had a start and end socket on it. That way as you are generating random tiles ahead of the player, you can use the end socket’s location and rotation on the current piece to snap the next tile’s start socket to. The spline component can also make use of these sockets for it’s start and end points using a construction script. (Be sure to also calculate the correct tangents for those points so you don’t get a kink when crossing to a new tile).

It’d be like snapping together a line of puzzle pieces if going straight, but would also work for bending left/right. One thing to be careful is making sure the track doesn’t loop around back onto itself, but even here you can use the rotation of the end socket to be clever about what pieces you pick next. Let’s say you generally want the track running down the +X axis… If you ‘Dot’ the forward vector of the last end socket against [0,1,0] and get a value closer to 1.0 that means you’re bending too far towards the right and should pick some track segments that go left with a higher probability. Just as an example.

If the current floor tile knows who the next tiles is, and you’re keeping track of your distance along the spline - when you get maybe 90% along its length you can tell your character to start tracking to the start point of the next spline given everything will match up at the socket locations in little segments like you mentioned.

thanks for your quick response. I was following epic’s endless runner tutorial so I knew how to spawn a randomly generated course, I wasn’t just aware of how to do it with a spline :slight_smile: Though instead of a socket I put an arrow component at the end of the tile and getting its world transform to add the next floor tile. I’m relatively new to splines and I will try to implement your solution this evening.
Probably you could post a picture of the spline setup? Thanks in advance.

This is rather old but I’ll give it a shot anyway.

So, a couple of things:

  • the curvature in Subway Surfers is not done by using curved meshes. The game is actually one whole straight line, and the curvature effect is actually a shader applied to every material in the game. I’ve done it, I can show you how

  • did you ever implement the spline idea? I managed to get some sort of 3-lane system (I keep the lane as a variable and moving my actor’s vector based on variable…a switch case basically) and it works fine, except it’s not very precise and I’m looking at ways to correct any deviations (sort of like a snap to one of the 3 lanes on each platform feature

like everybody else here, I’m using the endless tutorial - done it and currently improving on it. Got my own variant of the magnet running too.