Hello Everyone,
We are making a multiplayer pong game using Unity Netcode.
The ball is synchronized across all game clients.
The expected outcome is :
- When we press the mega shoot button on the client machine, we want to change the direction of the ball instantly without any weird jumps or jitterings.
All our tests are made through localhost (so no latency from the network is involved) with powerful computers.
What we tried :
1) First Test :
We set the GhostAuthoringComponent of the ball to Interpolation
=> the ball was moving smoothly but when we pressed the mega shoot button, there was a latency before the ball changes its direction (this outcome ruins player experience).
Conclusion of the first test:
The ball belongs to the server but it needs to be predicted by all clients, in order to have a good player experience.
Basically all client needs to change the ball position without waiting for the server’s response.
2) Second test:
So we changed the GhostAuthoringComponent of the ball to Predicted
=> When we pressed the mega shoot button, the ball was changing immediately its position but during the transition, the ball was jumping back and forth before taking the correct direction. The ball is less smoother than interpolation.
Here is the observed behaviour:
And here is the code that change position of the ball inside GhostPredictionGroup:
[BurstCompile]
[RequireComponentTag(typeof(BallTagComponent))]
struct ShootBallJob : IJobForEachWithEntity<Translation, PhysicsVelocity, PredictedGhostComponent>
{
public uint currentTick;
public float ball_positionX;
public float ball_positionZ;
public float ball_directionX;
public float ball_directionZ;
public void Execute(Entity entity, int index, ref Translation position, ref PhysicsVelocity velocity, [ReadOnly] ref PredictedGhostComponent prediction)
{
if (!GhostPredictionSystemGroup.ShouldPredict(currentTick, prediction))
return;
position.Value.x = ball_positionX;
position.Value.z = ball_positionZ;
velocity.Linear.x = ball_directionX * 2;
velocity.Linear.z = ball_directionZ * 2;
}
}
Any help on how to remove this jittering is welcome!
Thanks in advance for your help