Need Basic Explanation

Hi, I’m pretty new to Unet (like most of us) and I need to understand some basic things.
I’m making a racing game and I want to add multiplayer. I managed to set up the NetworkManager, NetworkIdentity etc… so when i’ve started a local game both players had control over their car. I’ve added 4 Network Transform Child components for each one of my wheels, so that the other players will see them spin and turn (I hope this is the right way…)
When i play, the car is very very laggy. I’ve tried to increase the Network Send Rate but i still get the same lag, How can i make the overall game smoother? I should point out that in the game the cars are very fast, and i want to get at top speed as less lag as possible.

Also, the only 2 things that i need to transfer to all the other clients are the car lights(are they on or off) and the car audio.
If both lights and audio are in arrays, how can i synchronize them to the server and what methods should i set as commands (just explain to me in general what should i do)
The car script is not mine, i’m using RealisticCarController…

I hope that you can understand somthing and help me, my english is not amazing.
Thanks

Hi!

I’m not at all that experienced with this, but after reading into some methods of handling lag between clients, I’m not entirely sure the network transform alone can do what you want it to do.

My experience with the network transform is that it is inherently laggy no matter the settings unless you set it to sync a rigidbody or whatever.

I think what you might want to look into is a type of client side prediction, and smooth out the resolved positions when you verify with the server position.

For my game I had to do this by sending inputs, the ticks of the inputs (just an int holding number of frames since start as a reference of time on both sides) and then send back the resulting position after the server controller moved based off the inputs.

Since there is a delay, while the server is waiting on a message or the client is waiting on a result, it can move normally using logic on the client itself. Ultimately, when it receives the correct position from the server, it compares that position and time with where it was at that same tick, resolves the error, and continues on its way.

I’ve read somewhere that racing games typically use a form of this called “dead reckoning” that base it’s client prediction on velocity.

For the other clients however, which is the more immediate concern, you have to smooth that movement out using either lerp or another way of smoothing out intermittent positioning.

You might could look into historic interpolation, I saw a YouTube series by Gamer to Game covering unet a while back and in one of the earlier episodes he implements a pretty simple form of historic interpolation to smooth out movement.

I’m sorry if none of this is helpful, but I think at the most basic level the problem is that on your clients, their position is only being updated at a set interval, something like 9 times a second if it’s default network transform if I remember correctly, so you can see the stutters. You need to get those positions before the player moves to them, and lerp to them to smooth that out. Historic interpolation keeps a buffer of those positions and acts slightly in the past, always keeping track of the next position to lerp to.

Best of luck to you, this stuff is pretty tough to tackle, at least for me, but once you get something working well it’s very satisfying.

1 Like

This is very helpful, thank you for your quick answer!
I saw the Youtube tutorial too and i thought about making the Network Transform manually.
I used his scripts and i still got terrible lag, this is why i’ve posted this thread, i really dont know how to make the game smoother

So, your cars being very “fast” has nothing to do with Lag. You have to remember that you’re moving your cars around in virtual space, so speed is all relative to the size of the cars, the size of the world you’re moving them around in, and how fast your making it “seem” like they are moving.

I think what you’re probably missing is the lerping aspect of movement which seems to be shoddy at best with a network transform.

Try to follow along on this and see if you can fix it: