# How do I limit movement in UE4?

**URL:** <https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196>\
**Category:** Character & Animation\
**Tags:** limit, unreal-engine, UE4, question\
**Created:** [August 21, 2019, 4:24pm UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196 "2019-08-21T16:24:18Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gunim](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gunim](https://forums.unrealengine.com/u/Gunim)\
**Post date:** [August 21, 2019, 4:24pm UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/1 "2019-08-21T16:24:18Z")

</div>

![285504-trials-evolution-1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/c/e/9ce56a8072d44e2f9924b05fcc0e5fc6811e7114.jpeg)

I’m trying to make a game similar to a screen shot.  
The player rotates only one axes.  
And the player moves only forward, backward, up, and down.  
If the player’s front wheels don’t rotate left or right, they will go just straight.

But an external shock will cause the player to rotate, and eventually run in the wrong direction.

What should I do to limit movement?

---

<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:** [August 21, 2019, 6:23pm UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/2 "2019-08-21T18:23:45Z")

</div>

Inside the player character, there are nodes which start the forward / backward and left/right movement of the player. Just disconnect the left/right will do the trick:

 ![285505-movement.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/f/3/2f3cac80451f33f3bad5063bbfe12de37fdc26a6.jpeg)

Obviously, in the end you need to program around it, I’m only suggesting disconnecting it to see if that’s what you want…

---

<div class="post-metadata">

**Author:** ![Gunim](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gunim](https://forums.unrealengine.com/u/Gunim)\
**Post date:** [August 21, 2019, 7:08pm UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/3 "2019-08-21T19:08:09Z")

</div>

Removing input keys is easy.  
But I can’s stop it from stepping on an irregular rock and changing its course.  
That’s my worry.

---

<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:** [August 21, 2019, 7:49pm UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/4 "2019-08-21T19:49:59Z")

</div>

You could also store the player’s world alignment when the level starts, and hold to the player to that alightment with tick.

---

<div class="post-metadata">

**Author:** ![Gunim](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gunim](https://forums.unrealengine.com/u/Gunim)\
**Post date:** [August 21, 2019, 8:16pm UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/5 "2019-08-21T20:16:03Z")

</div>

That’s the way I’ve been looking. Would you give me a little more detail?

---

<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:** [August 21, 2019, 9:10pm UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/6 "2019-08-21T21:10:23Z")

</div>

It’s hard to tell without actually seeing it, but you could use something like:

 ![285510-store.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/d/71dbc33d2fcf6eff81eaacce1a9d9659ca2bf624.jpeg)

to store the initial Z position, and then:

 ![285531-correct.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/8/3/a830f7c4ae237bd336c3a263cb1e096779724728.jpeg)

to correct it. This kind of tick arrangement means the player will always tend ( every frame ) to go back to the initial Z setting.

If you want to correct more settings, like a vector rather than a float, you can use the same setup but with vinterp.

I think it’s the player controller you need here, it might be the character…

I’m suspecting that it might not be enough. If the player gets knocked off course, the Z will correct, but by that time they will be slight off to one side. In that case you need to interfere with the code I was talking about above, the actual player control code. Just don’t let the left/right stuff happen.

---

<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:** [August 22, 2019, 7:14am UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/7 "2019-08-22T07:14:16Z")

</div>

Or, I suddenly thought, much better way, put the player on a spline. The spline can follow the track and you can use tick to make sure they stay on the spline 🙂

---

<div class="post-metadata">

**Author:** ![Gunim](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gunim](https://forums.unrealengine.com/u/Gunim)\
**Post date:** [August 22, 2019, 9:10am UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/8 "2019-08-22T09:10:15Z")

</div>

I’m testing from the Vehicle Advanced Template in UE4 4.22.3.  
I succeeded by modifying the method you told me, but there is a problem.  
x,y,z all the rotations are locked.  
The vehicle always tries to keep level.  
But location limit works properly.

 ![285573-20190822-174607.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/4/d/34d05bc7a8fd37235544c34aeb6091cbad2af018.jpeg)

 ![285574-20190822-174635.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/7/4/67459dfe4873dfdcdfa49583ca1d16656ac2c0aa.jpeg)

When I connect the GetPlayerController to the GetActorLocation, I don’t know why the player pawn’s position changes when I play the game.  
But disconnect, it works fine.  
I’m trying in many ways, but I haven’t finished it yet.

If I use splines, won’t there be problems with the jump?

---

<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:** [August 22, 2019, 10:41am UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/9 "2019-08-22T10:41:35Z")

</div>

Hi - Are you saying you can’t control the rotation? I notice your getactorlocation is not connected.

The controller controls the pawn, I - think - you’ll find if you try and affect pawn rotation directly with the pawn it wont work ( could be wrong ).

If you use a spline along the middle of the track, you can always let them do what they want, but you always know where to pull them back to. You don’t have to worry about ‘crawl’ where the coordinates gradually get more errors over time.

On the spline, you can let them do as much Z as they like, but get a grip on the XY.

---

<div class="post-metadata">

**Author:** ![Gunim](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gunim](https://forums.unrealengine.com/u/Gunim)\
**Post date:** [August 22, 2019, 11:15am UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/10 "2019-08-22T11:15:20Z")

</div>

Thank you for your answer.

I made the z-axis stop spinning only but the result was that all the axis of rotation stopped.  
If the x,y connection of the GetActorRotation is disconnected, the result does not change.

When the GetPlayerController and GetActorLocation are connected in the event Begin play, the vehicle is spawned elsewhere when the game is started.  
When the GetPlayerController and GetActorLocation are connected in the event Tick, the vehicle slowly comes down in the air and goes through the floor.  
When the GetPlayerController and GetActorLocation are disconnected in the both events, it works good.  
I don’t understand why this is happening. haha

Can I use splines to move the x,z-axes freely and limit the y-axis only?

---

<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:** [August 22, 2019, 11:20am UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/11 "2019-08-22T11:20:31Z")

</div>

Well, it’s really up to you how you code the spline thing. Just like now, you can limit only the bits you want. I think it would be more reliable.

---

<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:** [August 22, 2019, 11:21am UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/12 "2019-08-22T11:21:15Z")

</div>

Try it with PlayerPawn instead of controller, see if the rotation thing works…

---

<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:** [August 22, 2019, 11:24am UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/13 "2019-08-22T11:24:37Z")

</div>

Yeah, no, don’t do that 🙂

You need the controler ( like I thought ) and use the SetControlRotation node…

( you do set location on the pawn, no problem, but to do rotatation you have to talk to the controller with SetControlRotation )

---

<div class="post-metadata">

**Author:** ![Gunim](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gunim](https://forums.unrealengine.com/u/Gunim)\
**Post date:** [August 22, 2019, 12:18pm UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/14 "2019-08-22T12:18:02Z")

</div>

![285576-20190822-210702.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/8/8/6887908c267c28d2a8a49fc3d680c0c8db0f7aa6.jpeg)

Unfortunately, SetControlRotation does not work.  
All rotation limits are lifted.  
Maybe I should find a way to use the splines.

---

<div class="post-metadata">

**Author:** ![Gunim](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gunim](https://forums.unrealengine.com/u/Gunim)\
**Post date:** [August 22, 2019, 12:40pm UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/15 "2019-08-22T12:40:46Z")

</div>

![285578-20190822-213802.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/f/8/1f83ba92af8c0fdf57b5969ba989bbf04b9b4684.jpeg)

The problem that I’ve been thinking about for a long time has been solved in vain.  
Thank you for taking the time for me.

---

<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:** [August 22, 2019, 12:42pm UTC](https://forums.unrealengine.com/t/how-do-i-limit-movement-in-ue4/454196/16 "2019-08-22T12:42:26Z")

</div>

Ok, cool 🙂
