How to make a character to NOT stop moving in direction until I press the opposite button?

Hello. I’m new to Unreal Engine and I have been messing around with the Character Move Component on the third person template. I was wondering if I could be given help on a problem that I have been trying to solve in the event graph.

I have replaced the mesh with a simple object and I want the object, to NOT stop moving after I have pressed the button (W or D for instance). Instead - I want to use the opposite button (S or A for instance) to make it decelerate and then accelerate in the opposite direction and keep moving until a button is pressed again. The object should not turn round.

I’m wondering if this is something that can be done on the existing Movement Input, or will it need something separate?

Thanks.

Create a float type variable and continuously increase it while the forward movement key is pressed, and continuously decrease it while the backward movement key is pressed. Then, get your character movement component, drag the “Set Max Walk Speed” node out of it and insert that variable we’ve created in there, then plug that node after the Event Tick node. And after that, plug in the “Add Movement Input” node and insert the actor forward vector into it’s world direction pin.

Hey there @regionlocked! Welcome to the community! If you want tight control over the decel and accel functions, you may have to use the method VA mentioned. However the character movement controller does have a mechanism to control total acceleration and deceleration that can be applied.

image

image

If you make the braking deceleration lower and make the acceleration a bit less instant, you can slowly increase speed up to max and won’t stop on a dime when trying to stop. (This can feel like sliding on ice or walking in mud if its too low so avoid that).

Hello and thank you both for getting back to me. I should have mentioned that I am actually using the “flying” and not the walking. My apologies!

Will these methods apply to flying too? The flying tab doesn’t seem to have as many controls as the walking.

Thanks

I believe this applies to flying as well since flying as it’s just another movement mode (though definitely use the flying braking decel variable instead that isn’t pictured).

Not sure I have followed the instructions properly, but this does indeed keep the movement
continuous, but there is no deceleration or acceleration?

Where have I gone wrong?

It’s because you’re not increasing the variable while the input action for forward movement is pressed, or decreasing while the input action for backward movement is pressed. You should only plug in the variable as it is into the Set Max Fly Speed node after the Event Tick to update it continuously. The adjustment of the value should be handled after those input actions separately. To increase / decrease you can use ++ / - - nodes respectively, as simply using the addition node wouldn’t actually adjust the variable itself. And also make sure to add a delay before the increase / decreases

Thanks - will try that now.

I think what you may be looking for is something like (key event)>add or set velocity

I think I have made an error in my explanation - sorry.
What’s happening at the moment is that I press a key and the object starts moving which is great. It continues to move which is also great. However - it automatically starts to accelerate by itself. I would like to control when that acceleration happens myself.
That way I will have full control over it, to the point that I could even stop it moving altogether.

My apologies!
Would using the velocity be the key to this?

Are you talking about the situation in the blueprint code you’ve shown in your last screenshot? Because I don’t see anything about acceleration there. If not, could you also provide your latest attempt? And did you try my or SupportiveEntity’s suggestions correctly?

I think what I will do is animate my explanation and post a gif as I am doing a bad job of explaining!

I will post in the next 20 minutes while I set it up.

Thanks

3

Back again and hopefully this is better!

Key is pressed and the object starts moving. It will continue moving. If I hold down the button longer, it will increase in speed and stay at that speed if I were to let go of the button. I can increase it further if I wanted to by holding the button again.
If I hold the opposite button, it will decrease in speed. This means that I have full control on how fast I want it to go at any time.

The gif shows It can decrease to almost a stop. If I were to let go of the button, it would stay like that ( If the player is skillful enough). If I where to continue to press the button, then it would start to increase speed in the opposite direction - repeating all the above within my control once again.

Another example is like a physics game where it’s almost like a tug of war trying to balance the speed and direction with delicate precision.

Does this help?

Ummm… was that a question? :rofl:
I’m sorry I couldn’t see any issues in your explanation, it sounds like it’s working as intended :grin:

Sorry - that was an example of what I would like to happen. At the moment, when I press the opposite button, it accelerates by itself. It should only accelerate if I keep my finger on the button. :grinning:

Could you share some screenshots of your attempt? Please make sure to include all the related blueprint code.

Thanks for your help.

I tried to simplify the blueprint code. This is what I have at the moment. It just needs to not automatically acelerate by itself.

I have also noticed that when I move left and right when it is moving forward, it doesn’t move diagonally for some reason…

image

Here are the settings.

Did you try implementing my suggestion here: How to make a character to NOT stop moving in direction until I press the opposite button? - #7 by VisAgilis

I had tried adding the ++ and also the --. The result was that it started to move and then completely stopped moving altogether. It no longer moved when I was pressing the keys.
I have obviously done something wrong.

I will post how I connected it.