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?
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.
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).
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).
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
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?
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.
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.
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.