private void KalmanFPSIndependentCorrect(KalmanFilterComponent kalmanFilterComponent, Vector3 tankPosition, float dt)
 {
     kalmanFilterComponent.kalmanUpdateTimeAccumulator += dt;
     while (kalmanFilterComponent.kalmanUpdateTimeAccumulator > kalmanFilterComponent.kalmanUpdatePeriod)
     {
         kalmanFilterComponent.kalmanFilterPosition.Correct(tankPosition);
         kalmanFilterComponent.kalmanUpdateTimeAccumulator -= kalmanFilterComponent.kalmanUpdatePeriod;
     }
 }
        public void OnTankCreation(NodeAddedEvent e, RemoteTankNode node)
        {
            Entity entity = node.Entity;
            KalmanFilterComponent component = new KalmanFilterComponent {
                kalmanFilterPosition = new KalmanFilter(node.rigidbody.RigidbodyTransform.position)
            };

            entity.AddComponent(component);
            entity.AddComponent <RemoteTankSmootherComponent>();
            base.ScheduleEvent <PositionSmoothingSnapEvent>(node);
        }
        public void OnUpdate(TimeUpdateEvent e, RemoteSmoothTankNode node)
        {
            float deltaTime = e.DeltaTime;
            KalmanFilterComponent       kalmanFilter       = node.kalmanFilter;
            RemoteTankSmootherComponent remoteTankSmoother = node.remoteTankSmoother;
            Rigidbody rigidbody          = node.rigidbody.Rigidbody;
            Transform transform          = node.tankVisualRoot.transform;
            Transform rigidbodyTransform = node.rigidbody.RigidbodyTransform;

            this.KalmanFPSIndependentCorrect(kalmanFilter, rigidbodyTransform.position, deltaTime);
            float smoothingCoeff = deltaTime * remoteTankSmoother.smoothingCoeff;

            remoteTankSmoother.prevVisualPosition = this.SmoothPositionValue(remoteTankSmoother.prevVisualPosition, rigidbody.velocity, deltaTime, kalmanFilter.kalmanFilterPosition.State, smoothingCoeff);
            remoteTankSmoother.prevVisualRotation = this.SmoothRotationValue(remoteTankSmoother.prevVisualRotation, rigidbody.angularVelocity, deltaTime, rigidbodyTransform.rotation, smoothingCoeff);
            if (PhysicsUtil.IsValidVector3(remoteTankSmoother.prevVisualPosition) && PhysicsUtil.IsValidQuaternion(remoteTankSmoother.prevVisualRotation))
            {
                transform.position = remoteTankSmoother.prevVisualPosition;
                transform.rotation = remoteTankSmoother.prevVisualRotation;
            }
        }