Multiplayer Race

Hi all,
Trying my luck here one more time:
I’m working on a racing game but I get a weird problem when I try it in multiplayer - The client drives way faster than the server.
I followed the famous space dust racing tutorial (Space Dust Racing UE4 Arcade Vehicle Physics Tour - YouTube) and I got pretty good results for single player, but applying force (when driving and when using a speed power up) is not the same on the clients.
This is what I’m using to drive forward/backwards:

Anyone know what seems to be the problem?

Dont use “Server move forward”. What you should replicate is player input. So there is axis input from 0 to 1. You replicate that. And client (on the server side) only should know if accelerate or steer is applied, or not. If you replicate physics, it will follow what server is doing. Of course, you must allow client on the client side to do some sort of prediction of the movement so it does not fall behind.

This is how I done multiplayer in my game, and it works good.
Other thing, you should worry about is FPS differences on client and server, and that is beast of it’s own. It also differs if you use fixed or variable FPS.

I paid for this tutorial, and it’s awesome. I would strongly recomend it.

I believe the issue here is network latency. Given this, the server and client are out of sync when the section of code is executed and since the server wins when there are differences you get this behavior.

I believe the correct thing to do is to make your own version of character movement and leverage the custom movement slots that UE has available. This way your movement can leverage the built-in correction and prediction logic that is available out-of-the-box for walking, falling, swimming and flying.

Only other short term work around is that you know there will be non-zero latency. So, call the server event first and then do the client AddForce second. This will help align the server AddForce and the client AddForce; however, this does not solve the issue.

I have the same problem for sprinting.

My plan, unless you discover a better/easier way, is to follow this tutorial…

I take it there’s no way to do it in blueprint, right?

I don’t know. I have not found it yet…

Technically it can, but if you want to do it right, you must go through C++

I just followed this video and created a new test character…

It appears you/I will have to port all of the logic from your existing character to this new character which is implementing the expanded, or improved, character movement.

It seems you need to create both a new character movement and a new character which utilizes that new character movement.

The above video is for 5.0.3; however, I was able to get this code to work, compile in both C++ and BP, on 4.26.2. Have not tested it in my game yet…

In Listen Server mode the host is client and server at the same time so you are applying the force twice.
In the top branch you should add an authority switch, and only add force in the Remote case.

@Chatouille @Bojann @vespineauto007 First of all, thank you three for taking the time and trying to help - Much appreciated.
I’m not really a programmer of some kind, I’m originally a 3d artist who took some Java programming classes and now I’m at the point where single player is easy and multiplayer is ruining my life :slight_smile:

@vespineauto007 I don’t know if this will work in my case. The driver is not a child of character class, it’s a child of Pawn class. It doesn’t have the character movement component.
There’s the vehicle movement component, but I decided a while back not to use it and follow the Space Dust Racing (Obliteracers) tutorial for a more simple and stylized feel.

@Bojann What do you mean if I want to do it right? what’s the difference?

@Chatouille Your solution did solve that issue, but I don’t know about the latency issues. For example, I am experiencing some issues when starting the level - sometimes some players are jittering on start and don’t function correctly.

First of all, thank you three for taking the time and trying to help - Much appreciated.
I’m not really a programmer of some kind, I’m originally a 3d artist who took some Java programming classes and now I’m at the point where single player is easy and multiplayer is ruining my life

Don’t think it’s not ruining our lives too :smiley:

What do you mean if I want to do it right? what’s the difference?

You need to do proper network interpolation. What if server has 60 FPS, and client has 30 FPS? Or vice versa. What if there is latency. What if you need to have menu popup (pause game) if player controller is disconnected? Many things are not exposed in Blueprints. Online game is not a simple thing.

1 Like

That’s a good point. If that’s the case I’ll definetly have to convert my project from blueprint to c++ and learn it.