Hey everyone,
I’m working with a prediction v2 CSP character (using a Rigidbody) and a CSP Rigidbody ball in FishNet. I’m trying to add external forces to the ball from the character. I’ve attached a collider and a NetworkTrigger to the child of my player and used PredictionRigidbody.AddForce
to add force to the ball. However, this results in noticeable jitter on the client side. All collision responses and other physics interactions work flawlessly without using AddForce
.
How can I implement this feature without experiencing jitter on the client side?
Thanks in advance!
Scripts I’m using:
ControllerWithPrediction.cs (7.1 KB)
RigidbodyBallPrediction.cs (3.1 KB)
KickTriggerHandler.cs (1.9 KB)
BallKickHandler.cs (333 Bytes)
Fishnet Version: 4.3.5R
Unity Version: 2022.3.11f1
Client Jitter Demo:
There could be an issue with your BallKickHandler.
I was not able to fully review the scripts, but at a glance it looked like maybe you were blocking multiple hits to prevent excessive kicks. This will let the client kick the ball the first time, block them, but then when they reconcile they cannot kick during the replay because the kick is blocked.
A simple test could be to only check against the ‘is kicking’ when NOT reconciling.
eg: if (!predictionManager.IsReconciling) checkCanKickBall.
I’ve modified the script like this:
void Kick(Collider obj) {
BallKickHandler ballKickHandler = obj.GetComponent<BallKickHandler>(); // To prevent kicking the ball multiple times in a short time
if (!PredictionManager.IsReconciling) {
//When NOT reconciling, we can check if the ball is getting kicked
if (ballKickHandler.isGettingKicked) return;
ballKickHandler.isGettingKicked = true;
ballKickHandler.ResetKickAfterWhile(); // This will reset the state after a while (100ms)
}
RigidbodyBallPrediction ballPrediction = obj.GetComponent<RigidbodyBallPrediction>();
Vector3 velocityNormalized = rigidbody.velocity.normalized;
Vector3 dir = (obj.transform.position - transform.position).normalized;
dir += velocityNormalized; // Final dir contains the sum of the normalized velocity and the normalized direction
ballPrediction.PredictionRigidbody.AddForce(dir * kickForce, ForceMode.Impulse); // PredictionRigidbody.Simulate() will be called in the Replicate method in the RigidbodyBallPrediction.cs
}
But the issue still persists.