Download

AddMovementInput not working in network

Hi!,

I have a character that is owned by a player controller that was generated the moment the player connected.

My problem is when I send through a RPC of type server from the PlayerController of the client, an AddMovementInput() which correctly receives the value of the Vector passed by the player in the RPC function, which is executed correctly, but the character does not move.

If I change my RPC to Client it is called AddMovementInput () again it runs exactly the same, but in this case the character is moving but with lag, so i want to enable the server to move the character but im not able, only the client can do.

i have try activing bRunPhysicsWithNoController in the character controller but AddMovementInput still not working.

The Character system has a dedicated (and complex) built in system for networking.

What you need to do is ensure that the controller “posesses” the Character, and you can then call AddMovementInput() locally (without any RPC’s). Generally it’s better to do this in the Character rather than from the Controller.

The Character Movement system handles the rest.

Yes im doing in that way, moving locally from character and it works it move the Character but if the player connected have more than 80ms of ping, character moves like this: https://www.youtube.com/watch?v=fgaiQM8SzkQ

So i was trying to move the character from the server to avoid this.

Do i have any alternative to move the player from the server or to avoid the player moves with lags when im adding the input locally?

Thanks for your reply @TheJamsh

This jittering is serveur correction,

There is something you do wrong, as if the character movement componenent is correctly setup, the experience should be totally smouth, even with a ping as 80ms.

  • You move with keyboard ?
  • Do you change the value of network smooth in the character movement componenent ?
  • I don’t think this is the issue but, assure your display mesh have no collision (only the capsule component should have).

The best is to show us you’r code, so we can help you with more accuracy.

Hi!

  • I have tried with keyboard and joystick.
  • Yes i did i had test change the network values in the Character Movement component like the frequency update for position, but nothing changes.
  • Im sure is not a collision.

Here is a sample of my code:



UFUNCTION(Server, Reliable, WithValidation)
void horizontalMovement(float input);

void AMainPlayerController::horizontalMovement_Implementation(float input) {
APawn* actualPawn = this->GetPawn();
AMainCharacter* ch_ = Cast<AMainCharacter>(actualPawn);
if(nullptr != ch_) {
ch_->horizontalMovement(input);
}
}

void AMainCharacter::horizontalMovement(float input) {
if(is_player_alive_ && !lock_movement_) {
if (Role == ROLE_Authority && input != 0.0f) {
controller_rotation_2_.X = -input;
AddMovementInput(camera_right_ * input,1.0f,true);

//FVector actualPosition = GetActorLocation();
//FVector newLocation = actualPosition + ((camera_right_ * input))*20.0f;
//SetActorLocation(newLocation);

}
}
}


If i use a SetActorLocation it work it move, but doing like thid break all the movement component and my animation attached to the velocity.

If i use Unpoosed i apply the AddMovementInput() the player now move, but i lost the control of the character.



AController* playerController_;
playerController_ = GetController();
UnPossessed();
AddMovementInput(camera_right_ * input,1.0f,true);



UFUNCTION(Server, Reliable, WithValidation) void horizontalMovement(float input);

First thing : movement component handle the network, you should not replicate by yourself, but let the movement component.
Try to just add move input locally, and that should worlking fine, in network.

The only reason the character moves that way is because it isn’t setup correctly - You should not be sending any RPC’s at all.

The Character system does not need any extra networking functionality, it does everything for you. All you need to do make sure the client has possessed the character, and the client alone calls AddMovementInput. If you don’t possess the character, it will not work properly.