Endless Runner: centering the player on a lane after turning a corner

I am currently creating an endless runner game and I have come across a problem I am struggling to fix as a beginner. So far, I have set up the ability to rotate when coming across a corner and the ability to switch lanes. However, after turning a corner, there is a high chance that the player will not become centered on a lane. My idea was to add three box triggers that would split up the corner floor tile and center the player on a lane depending on which trigger is overlapped with.

However, I have no idea how to create a function which would do that. I tried creating something that would change the world location of the character and fiddled around a bit more but I am fully stumped. I have set up the tile system using the tutorial posted by the unreal team. I would appreciate any help. Thank you. Here are photos of my blueprints:



If you use tick to center the player, you don’t need to worry about any of this, I don’t think.

To get it working, just use tick ( with a vinterp ) to center the player on the pivot point axis of the current piece. Then you can add lanes, which is just an offset.

Sorry, I’m still a bit unsure on how to implement this. By “piece” do you mean the current floor tile actor the player is standing on? I don’t really understand use pivot points and all that. I have arrow components on the three lanes of my floor tile. Is there any way I can move the player based on the location of them?

I don’t really know your setup, so it’s hard to give you exact code. But let’s say the player is always running forward on X, Z never changes, so it’s Y you have to control.

Then, you need to home in on the Y coordinate of the arrow for the lane, a bit like this:

( You do this in addition to whatever you’re already doing to get the character to move forward ).

Thank you for the reply.

My issue is that its sometimes not the y axis which needs to be modified because after rotation the direction which the player is moving in changes.

Ok, same concept, but taking that into account. Sorry, will give an example when I get a mo… :slight_smile:

Ok, it turns out that it’s a bit of a mare, if I assume the arrows can be pointing in any direction.

If you calculate the arrow world position, arrow forward vector and the player world position, this handy little formula will tell you the nearest point on the line of the arrow which the player should head towards:

I have tested it :slight_smile:

intersect

So, something like

You will probably have to omit Z, otherwise the player will be half in / out of the tiles maybe.

You’ll need to tell the player which arrow is the current one as it changes. I really don’t know how much use this be, but it’s ( a little bit ) interesting…

1 Like

hi ive just seen your Endless Runner: Centering The player answer, i just wanted to know where you get the “Nearest Point on Line” target from? is it just the target promoted if so can i see what the first image’s full blueprint is connect too?

I’m just setting a variable there. Just drag the variable in to the graph, and choose ‘set’.

BTW, I did something else about endless runners here ( which is a spline on tiles ), it’s much more straightforward:

thank you for replying but how do i get this node
fgvt

also when im reaching the sport where i added the spline it snaps. Will the at end node solve this?

It’s in that post

Yes, that’s what ‘at end’ is for, to allow the player to cross between tiles.