Pathfinding of the pawn of a player controller in a networked game

Hello,

I’m developing a basket ball game.

I would like, when a basket is scored, to move all players to pre-defined spots on the court, where they will be able to do the throw in.

To move the bots, I use the function AAIController::MoveToLocation, and everything goes fine, either in a standalone game or in a networked game.

The problem is with the player controllers: in a standalone game, everything is fine, whereas when networking is involved, the pawns move to their destination, but the movement is jerky.

To make the pawns of the player controller move, I tried two solutions (which are pretty similar):

  • The first solution was to use the UNavigationSystem class, and call SimpleMoveToLocation on it.
  • The other solution consisted in implementing in my custom PlayerController class almost the same code found in AAIController. But the result is the same as the code above.

My guess for the jerky movement is that the component which manages the position the pawn must be along the path is in conflict with the server movement prediction.

I’ve started to dig in the source code of PlayerController, to check if I can override a function to disable this behavior while the pawn is in pathfinding mode, but I didn’t have much success until now.

I was also thinking to another solution, and I’d like your opinion about that: do you think it would be a good idea, when I use pathfinding on a player controller, to switch the controller of the pawn to an AIController, then execute the path finding and the moving of the pawn to the desired location, and when the pawn is there, switch back to the previous PlayerController?

Or do you think there may be another solution?

Thanks in advance

You could change the PlayerController to another controller and, when the game is “restarted”, return control to the PlayerController.

Yes, that’s what I did in the end. When I spawn a PlayerController, I also spawn a AIController, and when I want to control the movement of the player pawns, I switch the controller.

But I have the feeling it’s a bit of a hack. Isn’t the conflict between network prediction and pathfinding a bug? (given this is the real problem of course)

Why not execute the pawn movement on the server? If the pawns are set to replicate movement this should then happen on the clients and since it’s being done on the server it shouldn’t try to enforce any corrections.

The pathfinding is already done on the server

Have you find any solution to this problem? I see the same behavior when making a multiplayer version of the TopDown template. I replicate the mouse click (hit position) to the server, where the movement to the position is done, which should be (at least in my mental model) replicated to the clients via the character replication. That is how it looks like:


However what I see is a jittery and slow movement of the client character, where the server character moves and replicates normally. I’d be grateful for any help. It feells like I didn’t understand smth. basic about the character replication but I don’t know what exactly.

In case anyone else is looking for a solution to this problem like I was, the solution is actually pretty simple.
All you need to do to get rid of the jitter is to overload the SendClientAdjustment function in your player controller and return immediately rather than calling the base class implementation while the pawn is pathfinding.
As far as I understand this function is usually used to reconcile the player’s position on the server with the one from the client, assuming that the client has the more “correct” position. This however is only true while the player is directly controlling the pawn’s movement. Since pathfinding runs on the server, simply skipping this “correction” in the meantime will allow the movement to be replicated without interference.

1 Like