Hi all,
I’m seeing unpredictable and jerky character movement when in a networked scenario and was wondering what approaches you guys have taken to work around it.
I have taken various approaches and seen differing results, none of them to an acceptable standard. In this scenario, I have two players: one is the server, and one the connecting client. When the server player moves, it is smooth for both him and the client - no problems there. When the client player moves, it is not smooth, and jerky for one (or usually both) of the players. Presumably this is the server attempting to correct the position of the client.
My current process is as follows: I have a custom component for movement:
UCLASS()
class CUSTOM_API UCustomCharacterMovement : public UCharacterMovementComponent
{
Within this, I have a function set up to request movement:
UFUNCTION()
void MoveCharacter(ARoguelikeCharacter* character, const FVector& direction, float value);
void MoveCharacterInternal(ARoguelikeCharacter* character, const FVector& direction, float value);
UFUNCTION(Server, Reliable, WithValidation)
void ServerMoveCharacter(ARoguelikeCharacter* character, const FVector& direction, float value);
virtual bool ServerMoveCharacter_Validate(ARoguelikeCharacter* character, const FVector& direction, float value) { return true; };
virtual void ServerMoveCharacter_Implementation(ARoguelikeCharacter* character, const FVector& direction, float value);
This is very basic: the character calls “MoveCharacter” - if they have authority, they call MoveCharacterInternal, else they call the server RPC function, which in turn calls the internal method. The body is as such:
character->AddMovementInput(direction, value);
This process is begun at the press of a button - so if the player presses or holds W for example to walk forward, this function is called per tick.
So it is very basic. This annoyingly results in jerky movement - the client character will often realign to new locations as the server decides where it should be.
Is there a better approach? What solutions have other people taken?