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

**URL:** <https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945>\
**Category:** Blueprint\
**Tags:** unreal-engine, UE4-26, Blueprint, question\
**Created:** [January 16, 2022, 11:44pm UTC](https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945 "2022-01-16T23:44:27Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_6d584b7a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6d584b7a](https://forums.unrealengine.com/u/anonymous_user_6d584b7a)\
**Post date:** [January 16, 2022, 11:44pm UTC](https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945/1 "2022-01-16T23:44:27Z")

</div>

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.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/3/6/361864edf444e424b8c708b1e9570394bd435a5a.jpeg)

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:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/7/5705c4870291828ad4cda9c539ff45de081ba2bd.jpeg)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/0/b/0b4298c980ef4876a1e48c238fdd930a4aefec4f.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/7/9/79c68c0e567ce63cb3bc6d5ce929ee6c4f3dbdb3.png)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [January 17, 2022, 8:19am UTC](https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945/2 "2022-01-17T08:19:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6d584b7a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6d584b7a](https://forums.unrealengine.com/u/anonymous_user_6d584b7a)\
**Post date:** [January 17, 2022, 11:15am UTC](https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945/3 "2022-01-17T11:15:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [January 17, 2022, 11:28am UTC](https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945/4 "2022-01-17T11:28:00Z")

</div>

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:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/b/e/be41349518fa8bc0dfb95f1dc6e548aeaf2492c8.png)

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6d584b7a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6d584b7a](https://forums.unrealengine.com/u/anonymous_user_6d584b7a)\
**Post date:** [January 17, 2022, 11:39am UTC](https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945/5 "2022-01-17T11:39:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [January 17, 2022, 3:53pm UTC](https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945/6 "2022-01-17T15:53:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [January 17, 2022, 8:32pm UTC](https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945/7 "2022-01-17T20:32:28Z")

</div>

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:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/4/2/4276f810c762ae3fffbfbe07f2aa9aeacf5ba888.png)

I have tested it 🙂

![intersect](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/4/54f8aab3d3a521040ce3556debbb4c68785eb78e.gif)

So, something like

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/0/503f63e75aa00f3bdd335b0f35d7492eb6707828.png)

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…

---

<div class="post-metadata">

**Author:** ![ozzy2478](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ozzy2478](https://forums.unrealengine.com/u/ozzy2478)\
**Post date:** [April 8, 2022, 12:51am UTC](https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945/8 "2022-04-08T00:51:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [April 8, 2022, 7:39am UTC](https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945/9 "2022-04-08T07:39:04Z")

</div>

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:

> [@Endless runner. Spline paths](https://forums.unrealengine.com/t/endless-runner-spline-paths/461999/15):
>
> That’s the whole thing…

---

<div class="post-metadata">

**Author:** ![ozzy2478](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ozzy2478](https://forums.unrealengine.com/u/ozzy2478)\
**Post date:** [April 9, 2022, 12:23am UTC](https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945/10 "2022-04-09T00:23:24Z")

</div>

thank you for replying but how do i get this node  
 ![fgvt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/1/d/91decec1538fdd392e720da23fb24d3f837fdb61.jpeg)

---

<div class="post-metadata">

**Author:** ![ozzy2478](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ozzy2478](https://forums.unrealengine.com/u/ozzy2478)\
**Post date:** [April 9, 2022, 12:29am UTC](https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945/11 "2022-04-09T00:29:47Z")

</div>

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

[https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/b/a/cba45e0fca59308e3f9579c5abcb3369f9897990.mp4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/b/a/cba45e0fca59308e3f9579c5abcb3369f9897990.mp4)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [April 9, 2022, 8:25am UTC](https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945/12 "2022-04-09T08:25:46Z")

</div>

It’s in that post

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/0/f/30f14e902e3171c59ec8082810a5d85deb282023.png)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [April 9, 2022, 8:26am UTC](https://forums.unrealengine.com/t/endless-runner-centering-the-player-on-a-lane-after-turning-a-corner/272945/13 "2022-04-09T08:26:27Z")

</div>

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