How do I limit movement in UE4?

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?

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:

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

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.

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

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

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

to store the initial Z position, and then:

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.

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 :slight_smile:

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.

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?

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.

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?

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.

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

Yeah, no, don’t do that :slight_smile:

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 )

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

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.

Ok, cool :slight_smile: