private void MyUpdate(float deltaTime, MJPlayerController.PlayerInputForPacket playerInput) { //Move client side prediction Move(playerInput.MoveDir3D, deltaTime, playerInput.Boosting); RotateTo(playerInput.LookDir3D); var clientPredictedPosition = transform.position; var clientPredictedRotation = transform.rotation; var tempSpeed = oldSpeedVector; //Move using server prediction transform.position = predictionServer.position; transform.rotation = predictionServer.rotation; oldSpeedVector = predictionServer.speed; Move(playerInput.MoveDir3D, deltaTime, playerInput.Boosting); RotateTo(playerInput.LookDir3D); predictionServer = new PredictionServer(transform.position, transform.rotation, oldSpeedVector); var lerpedPredictedPos = Vector3.Lerp(clientPredictedPosition, predictionServer.position, lerpAmountForReconciliation); var lerpedPredictedRot = Quaternion.Lerp(clientPredictedRotation, predictionServer.rotation, lerpAmountForReconciliation); transform.position = lerpedPredictedPos; transform.rotation = lerpedPredictedRot; oldSpeedVector = Vector3.Lerp(tempSpeed, predictionServer.speed, lerpAmountForReconciliation); }
// Use this for initialization void Start() { characterController = GetComponent <CharacterController>(); predictionServer = new PredictionServer(transform.position, transform.rotation, Vector3.zero); }