Download

[4.9.2] Need help with network/replicated Pawn Movement

Im trying to set up a space based game in which a variety of “equipment” has reaching impact on how the players pawn moves.
To that end Ive set up a system that in general acts in the following manner:

Player Controller gets mouse click and sets the hit location to an OrderLocation variable in the Pawn.
OrderLocation is replicated using a server function:



Set**OrderLocation**(FVector  Location)
{
  if (Role < Authority) **OrderLocation** = Location;
  ServerSet**OrderLocation**(Location);
}
OnRep_**OrderLocation**()
{
}
ServerSet**OrderLocation**(FVector  Location)
{
  **OrderLocation** = Location;
}


In Tick() a bunch of code is called to determine how to face, how fast and when to move towards the OrderLocation, and when and if the pawn should strafe side to side to avoid obstructions, ect…
This code outputs an FVector NewVelocity variable that is directly added to the pawns velocity via GetCharacterMovement()->Velocity = NewVelocity;

Every thing works fine in single player but when testing over a network for multiplayer, the Server’s version of the Client does not match the movement(or rather the lack thereof) of the Client when said Client comes to a stop.

Instead the Server Version of the Client acts as if it has not yet reached its OrderLocation, and continues to move and loop around to the OrderLocation even though it clearly knows where the OrderLocation is. It also jitters while doing this. The Server Version of the pawn moves fine as long as the Client Version is moving, it only starts jittering when the Client Version stops.

Any thoughts on what might be the problem/ or what I might need to do to fix this would be GREATLY appreciated.
All my previous work has made use of the default AddMovementInput() calls for Pawns, this is the first time trying to get custom movement through directly interacting with the CharacterMovement’s velocity.

Ok I made some changes and got some results:



SetOrderLocation(FVector  Location)
{
  if (!(Role == ROLE_Authority && !IsLocallyControlled()))
  {
    OrderLocation = Location;
    if (Role < ROLE_Authority && IsLocallyControlled())
    {
      ServerSetOrderLocation(FVector  Location);
    }
  }
}
OnRep_OrderLocation()
{
}
ServerSetOrderLocation(FVector  Location)
{
  OrderLocation = Location;
}


This gets a more consistently matching movement between Client and Server Version of Client, but now Server Version of Client is jittering while moving too.
Not all the time though. I have not been able to determine what the cause of the jitter is.

I think I fixed my problem, but It hinges on something I would like to confirm.
(I mean it appears to be working, but it might not be accurate depending on how I implemented it)

I changed SetOrderLocation() to:



SetOrderLocation(FVector  Location)
{
  if (Role == ROLE_Authority && IsLocallyControlled() || Role < ROLE_Authority && IsLocallyControlled())
    OrderLocation = Location;

  if (Role < ROLE_Authority && IsLocallyControlled())
    ServerSetOrderLocation(FVector  Location);
}


And then made sure that ONLY the Server ever changed or manipulated the pawn’s Movement Component.

So my question is:
Is it true that ONLY the Server Version of any pawn should ever change the values of the pawn’s Movement Component?