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.
answered Dec 20 '15 at 03:11 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here