How do I restrict my character's movement to one axis?

So I just started working on my very first UE5 project. Approach is to make a movement based game with sliding mechanic and I used two vids for reference and created a blueprint that decreases your mesh size and increases movement speed but to complete the illusion of sliding, I need it to lock my player’s direction to just the x-axis.


(released exec is the same as pressed except it resets the capsule size and speed)

to be mentioned : I do not have C++ knowledge

Is this a 2D game? Because if it isn’t, you’re almost NEVER going to just use one axis. The moment your character turns, BOOM, you’re using the Y-AXIS.

And what is the camera supposed to do in all this?

Can you post a video (you can link YouTube) showing the current behavior, and a video of another game with the intended result?

It is a 3D FPS but I want the character to be locked to one axis when someone presses left ctrl to do the “sliding” (in reality it’s just a crouching system that also increases your movement speed, creating the illusion of sliding).

Here’s a video of the current state:

What I want it to be is pretty much like the sliding in Ultrakill. In that game, it is restricted to a particular axis.

https://www.youtube.com/watch?v=94p9WzvzxBg (1:04)
This video showcases the sliding in Ultrakill pretty well.

Got it. But you’re not on one axis. You’re on two.

You need a way to preserve your Z-Value (assuming the surface is flat) and then accelerate your X and Y values.

sorry for replying late, thanks for the vid but i have already pretty much made that. i just want the character to be locked into one axis for the duration of the slide. is there no way to lock your player’s axis when you are triggering an event?

Then instead of it being physics based, you may just want to use an animation montage, and then the montage moves in the direction of the character’s most recent forward vector. While the character slides, you can DISABLE_INPUT.

And, you are mixing up PLANE with AXIS. You want the character to slide along a single plane, but, again, that character will be moving through two axes. This is an important distinction because if you go with the mindset that you are only using ONE of the COORDINATE values, your results will be inconsistent.

X, Y & Z are three axes in this right? Z is already out of the picture, between X & Y, I want to restrict the movement to one of them when you are pressing the input button for the sliding feature.

I will try that anim montage thing, let’s hope it works and sorry if im confusing things, i just started unreal 5 days ago :frowning:

also, if you could help me understand, how do i disable input?

This is only true if you are creating a 2D game where the character is ALWAYS moving along X (or Y). But in 3D, the character is constantly moving between X and Y, and occasionally uses Z.

If you want to test this, attach a GET_ACTOR_LOCATION node referencing your character to a print string, and you’ll see, even when you walk in a straight line, the Y value will change. The Z, unless you jump, will not.

in that case, can I atleast lower the speed of movement in Y axis when you’re sliding in X (& vice versa)? My main goal is to add this cripple to the movement so that you HAVE to get out of a slide to change the direction of your player.

that disable input part sounds interesting, would really appreciate if you could shed some light over that.

ALSO, when I mention the Axes, I am referring to the player’s axes and not the world. Sort of like, the capsule will be bound to move in that axis particularly.

You’re still not understanding, which is fine. Please, do this so you can see what I mean, because there’s a conceptual ocean between us.

Replace the skeletal mesh with whatever mesh your character is using. Now, try to walk in a straight line with your character, and pay attention to the X and Y values.

In 3D, you CANNOT arbitrarily change an X or Y value, because, the moment your character moves, they are in X and Y space. If you clip or reduce one of these values, you character will NOT slide in a predictable way.

Again, please do this, so you see what I mean.

(Analogously, in 2D, you can ignore ONE COORDINATE → Y, in 3D, you can ignore ONE COORDINATE → Z, in 4D, you can ignore ONE COORDINATE → W).

okay, I did check that and I understand how it is, let me replace the entire scenario with this, if you saw the video I attached initially, my player can currently move in all directions while sliding, as freely as walking, while holding left control (the input I have made for sliding).

is there a way to just lessen that freedom when sliding? In a way that WHILE sliding, the player can MOSTLY propagate in the direction we’re facing and pressing other directional keys has close to zero or less effect?

Again, I apologise as I am not aware of most of the mechanisms but I still want to give it a try.

CLEAR.

You can disable input and use the impulse/momentum applied to the forward vector of the character.

I do not know how you have it set up, if you have it set up at all.

There’s a few ways to do it.

So set it up, if you haven’t already, and if you need assistance, post a screenshot.

should i share my characterBP? You could take a better look that way.

I’m going to bed, so I’ll have to look at it in the morning (someone may intercept before me), but show the code that executes the slide motion.

oh it’s attached in the question, you can see it there. Again, at the current moment, it functions like crouching instead of sliding, while it increases the character speed to make it feel like a slide.

Okay, our wires are crossed, because you’re calling it a “slide” but it’s not; it’s a temporary SPEED BOOST.

But you want the SPEED BOOST to be controlled by the player; it’s not AUTOMATIC, the player MUST press FORWARD.

This was confusing to me.

Now I understand.

You’re going to need to place a BOOLEAN like, “Is boosting?”, that will block the ACTION VALUE X (Again, your use of the word “axis” confused me. Now I understand what you mean!).

It should look something like this:

Where, you’ll reference this Boolean value and switch it to true in your “slide” INPUT ACTION. When it’s TRUE, inputs referring to X INPUT VALUES (left and right) will be disabled until you flip the Boolean value again.

so i was trying to do the same but my Get Control Rotation and Get Right Vector does not have as descriptive options as yours?

is this a problem?

I don’t know if it helps or not, but on the Character Movement Component there is an option for constraining movement onto a plane, found under the group Planar Movement.

For the duration of the slide, you could just constraint the movement to the plane calculated from the initial direction and position (e.g. Set Plane Constraint from Vectors and Set Plane Constraint Origin).

Keep in mind that constraining the movement in this way is a “hard constraint”, so nothing can move the component out of that plane, including collision. This is something you might or might not want.

P.S.: IMO, this option is mainly used for side-scroller games to avoid pushing the character backward/forward accidentally.

This may not help him, but it sure helps me. Thanks!

1 Like