Sudden loss of movement speed when using acceleration curve in multiplayer as character approaches maximum speed

EDIT: Video of symptom can be seen here → Sudden loss of movement speed when using acceleration curve - Unreal Engine 4.21 - YouTube

For the last few months I’ve been battling this annoying issue whereby a game character in multiplayer will be running along and suddenly loose speed due to some weird network correction. I’ve whittled down the issue to what seems to be getting close to maximum speed while using a variable acceleration value.

I have attempted to work on the issue in blue prints, using UpdateMovement callbacks, custom C++ character and movement controllers and still I keep hitting this ■■■■ problem. Its really feeling like some bizarre bug. Especially when I can jam up the character’s max walk speed and the issue is deferred along.

1: Create a new project based off the Third Person template. Remove the walls around the level and expand the base floor to 50x scale in the X+Y so you have plenty of room to run around

2: Open up the “ThirdPersonCharacter” blueprint

3: Add a Float, name it “CurrentSpeed”

4: Add a CurveFloat, name it “AccelCurve”

5: Set two points in the AccelCurve to the following values

  • Time = 100, Value = 1000
  • Time = 1000, Value = 10

6: Create a Widget and name it “HUD”

7: In that widget, create a Text, and bind its text value to the “CurrentSpeed” of the character

8: While also in the widget, make a progress bar and bind its value to current speed. But ‘MAP Range’ the value range so 1000 = 1. Thus ProgressBar is full when speed is 1000

9: Back in the ThirdPersonCharacter blueprint

10: Set the value of MaxWalkSpeed of the CharacterMovement component to “1000”

11: Add to the blueprint event graph the following nodes

=============================

Testing:-

Start the game, in normal single player mode in the editor. Run around gathering up speed. You want to get to the speed of 1000.

You will notice as your spread increases the acceleration slows down.

Stop the game

Now start it up again but in Dedicated Server mode

Open the console and type in the following command

  • p.NetShowCorrections 1

Run around as you did earlier.

NOTICE: That as you reach the near the maximum speed of 1000, you will get movement corrections and you suddenly loose a MASSIVE amount of speed. Possibly dropping down to 600 to 800 speed.

Feel free to add additional debugging to compare your server speed and client speed. What you will see is that on the server it will suddenly show you slowing down for no real reason and because of this it’ll make a significant correction.

Try changing the MaxWalkSpeed to 1100, and notice the issue happens far less when hitting 1000. Set the value and see that the issue happens as you approach maximum speed.

This issue happens on 4.15, 4.19, and 4.20. Will try 4.21 soon after downloading it.

==========

Suggestions anyone?

==========

  • The end goal of this is to have a character that has the ability to sprint.
  • When they sprint, as they approach their maximum speed, their acceleration is reduced
  • Also there will be a stamina value which influences the acceleration AND maximum speed value.
  • Eg, if they are at half stamina, they can not accelerate as fast, nor can they reach a maximum speed like a well rested characher.
  • If they are out of stamina they can only sort of jog along and not run as fast as a well rested character. They would have to essentially walk/stop moving, to regain their stamina.

Older post here trying to look into the symptoms Adjusting the MaxWalkSpeed many times on a multiplayer game, stuttering - Multiplayer & Networking - Unreal Engine Forums

Also happens in 4.21.1

EDIT: And I’ve just realised the below forum thread is from UDK, and NOT Unreal Engine 4 related :frowning:

This forum thread also seems to describe similar symptoms and may be related.
How to REPLICATE VELOCITY instead of acceleration - Epic Games Forums

Note: I have used the code from GitHub - Pantong51/AdvancedMovementComponent: Jetpack added to the CharacterMovementComponent in UE4: Network Ready, Supports Rollbacks, Pretty basic for your own needs

which seems to get a lot of its design from the tutorial A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums

I’ve probably look at that tutorial at least once a month for half a year now, and I think I have a better understanding now of it all. :stuck_out_tongue:

The problem I’m seeing still seems to happen because I think I have a variable acceleration rate. Now if it was happening extremely often I’d suspect it would have been a similar symptom to changing MaxWalkSpeed or something every tick. But everything seems perfectly fine up until the point where you get close to the maximum speed. Thats when the reset of positions happen and the sudden loss of speed.

I also tried today a maximum speed of 500, and the issue did NOT seem to happen. But DOES happen when a max speed of 600 is set.

Yet still I can set the maximum speed to 2000, and just have a very low acceleration up to maximum speed and I dont seem to get the resets?

Video of the symptom can be seen here

I’ve also tried the above by using a custom character and movement component in C++ See attached ZIP

NOTE: If you use the code below. Make sure to disconnect the blueprint example above. You do not want the blueprint to be setting the MaxAcceleration variable of the movement component, otherwise you’ll be fighting with the C++ code.

NOTE: also there is some code in there for toggling between a walking and sprinting state. I have removed the bulk of it and it is not being used.

When you use the code, you manually set the SprintSpeedMaximum in the characters movement component

Heres the meat of it:-

float URW_MovementComponent::GetMaxAcceleration() const
{
	const FVector LateralVelocity = FVector(Velocity.X, Velocity.Y, 0.f);
	return SprintAccelerationSpeedCurve->GetFloatValue(LateralVelocity.Size());  //Return the acceleration curve value which matches the current speed the character is moving at
}

link text

For anyone seeing this years after the fact. I am now considering using General Movement Component to help with the sync between the player character and server positions. See link