Question about CharacterMovementComponent

Hi there,

do you know some sort of workaround to avoid that the Movecomponent loose all it’s velocity at the moment the input key (axis Mapping) is released? At the moment my char immediately stops moving at the moment when the key is released. This is especially odd when the char is sprinting (Speed 900) and when you release the key he is at Speed 0, so he basically snaps from Sprint to Idle, because the 2d blendspace works with direction and speed.

Any hint to fix this problem is highly appreciated.

Thanks in advance.

You could just gradually decrease the speed over a certain ratio. Although what you’re saying makes perfect sense, its normal that it isn’t included in the templates.

Just add a method for when the button is unpressed, when it is, gradually decrease the movement speed.

Thanks ,
I wrote a function yesterday that adjust the speedchange if MaxWalkSpeed != DesiredSpeed per 6.25f. It works very smooth to blend between the states as long as a axis input is there, but stops immediately once no input key pressed.

Is there an option to check key releases in the axis mapping? As far was I know Pressed/ Released only works with action mappings. I could add an action mapping too for the key release only, but I guess it will make remapping the keys in the menu a bit complicated

What I would suggest would be:

  • Add the released mapping for the keys (just map them to something like, OnForwardKeyReleased()), when the key is released, if applicable, start a timer which decreases the velocity every X time - just don’t forget to clear the timer when the input is restarted or when the player should stop. Another way - though not as reliable as can amount of ticks can vary according to frame rate - would be to decrease the velocity in the tick functions.

Hi there,

In the character movement component set the Breaking Velocity (or similar property) to lower values.

@ neo:

Thanks, unfortunally changing the Braking Deceleration value didn’t bring any change. I’ve even tried a extremly low value as a test.

@ .
Yes, as far as I can see at the moment, this is only approach that will bring a result. I’ll check the source code if there is a function in the CharacterMovementComponent or the PlayerController that let you check if there is any axis input…if not I’ll do the input released check to tigger a function to count smoothly down until the movespeed is 0.

I’ll also take a look in the vehilce game since with cars you also can’t stop as soon as you left the gas key.

In case if someone has a similar problem…this is how you could read your axis value, so binding another key is not necessary (at least in my case)

it’s tested and it works:

CharacterMovementComponent has both friction and braking deceleration implemented, so nothing special should be needed for this. If braking deceleration is not it, maybe check if friction is set too high?

If both isn’t making any difference, then there must be something wrong about how you apply the velocity. You should not set velocity directly, but instead use AddMovementInput and let the movement component do the rest. Perhaps this is the issue?

Hi Zenity,

adjusting the friction made it better, but it still didn’t fix it. Velocity was always added using AddMovementInput.

Debugging the velocity I’ve found out that there is a sudden drop in velocity for a few frames once the player left the axis input keys and the function took over…you didn’t even notice it with a non animation model, but a drop of 150 Units for a few frames is huge difference in the blendspace and therefore…it still snapped.

I’ve bypassed reading the speed from the velocity by direct output of the current Playerspeed to the animation blueprint and now everything works as intended…perfectly smooth

See the drop rate debugging the current playerspeed

be continued in the next post…

so…this was done and I went to implement sneaking.

I didn’t want to use the default crouch function because I want to use my own speed parameters to have full control over the animation and such…and of course, the camera
While my sneak function solve the speed thingy, the camera issue is persist as soon as I shrink the size for the player capsule. I need the camera in the exact same position before and after sneaking, however the camera boom is attached to the Rootcomponent which is the capsule and once the capsule shrink, the camera boom follows.

First I thougt “no problem, then I’ll just add the height difference as a z offset to the camera”…but once I debugged the camera position vector I’ve found out that it is still on the same z position (also x and y) as before…so maybe only the rotation is influenced.

Does anybody know a way to lock an actors position (location and rotation), even it if is only useful for debugging?

I also added the heightadjust to the length of the camera boom, but it only pushed the camera more far away, but still went down.
After my work I’ll continue looking for a solution.

If I can’t fix this I guess I have to add a second camera which will be activated during sneaking and stealth combat…or just not shrink the capsule, but this is actually the worst solution since I can’t use some nice features of crouching/ sneaking then.

ok, I have a solution in mind which will work…I’ll share it once I could test it latest today for anyone who could need it